zoukankan      html  css  js  c++  java
  • python数据可视化示例柱状图

    from matplotlib import pyplot as plt
    import platform
    import pandas
    from pathlib import Path
    
    # 根据不同的平台设置字体,不然无法显示中文windows
    platform_dic = {"Darwin": "Arial Unicode MS", "Windows": "SimHei"}
    plt.rcParams['font.family'] = [platform_dic.get(platform.system())]
    plt.rcParams["axes.labelsize"] = 30  # axes是轴字体大小调整
    plt.rcParams["xtick.labelsize"] = 20  # 横坐标字体大小调整
    plt.rcParams["ytick.labelsize"] = 30  # 纵坐标字体大小调整
    plt.rcParams["figure.figsize"] = [40, 15]  # 显示图像的最大范围
    
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    
    _result = pandas.read_csv(Path(__file__).parent / 'city.csv', index_col=False)
    result = _result.sort_values(by="price")
    # x,y轴数据
    x_arr = []  # city
    y_arr = []  # price
    for i in result.iterrows():
        x_arr.append(i[1].city)
        y_arr.append(i[1].price)
    
    """
    房价
    """
    plt.bar(x_arr, y_arr, color='rgb', label='The City Price Bar')  # 指定color,不然所有的柱体都会是一个颜色
    plt.gcf().autofmt_xdate()  # 旋转x轴,避免重叠
    plt.xlabel('城市名称', color='g')  # x轴描述信息
    plt.ylabel('定基', color='g')  # y轴描述信息
    plt.title('2019年3月70个大中城市新建商品住宅销售价格指数')  # 指定图表描述信息
    plt.ylim(0, 200)  # 指定Y轴的高度
    plt.savefig('2019年3月70个大中城市新建商品住宅销售价格指数')  # 保存为图片
    plt.show()
    
  • 相关阅读:
    【HDOJ】2774 Shuffle
    【POJ】2170 Lattice Animals
    【POJ】1084 Square Destroyer
    【POJ】3523 The Morning after Halloween
    【POJ】3134 Power Calculus
    【Latex】如何在Latex中插入伪代码 —— clrscode3e
    【HDOJ】4801 Pocket Cube 的几种解法和优化
    【HDOJ】4080 Stammering Aliens
    【HDOJ】1800 Flying to the Mars
    SQL语法
  • 原文地址:https://www.cnblogs.com/c-x-a/p/10820802.html
Copyright © 2011-2022 走看看