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()
    
  • 相关阅读:
    JAVA中使用FTPClient上传下载
    js 计算题
    js 中的call apply
    js闭包、原型、继承、作用域
    jQuery中.bind() .live() .delegate() .on()的区别
    Javascript中String、Array常用方法介绍
    常用函数
    事件委托,阻止默认事件
    【探讨】javascript事件机制底层实现原理
    css 垂直水平居中
  • 原文地址:https://www.cnblogs.com/c-x-a/p/10820802.html
Copyright © 2011-2022 走看看