zoukankan      html  css  js  c++  java
  • python 办公自动化操作之绘制折线图,柱状图,饼图

    折线图,柱状图,饼图用于数据展示,更直观的分析数据。实现绘制的效果图如下

     

     

    代码 很简单,如下

    import matplotlib.pyplot as plt
    
    plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
    
    #数据源
    date=['2018/7/21','2018/7/22','2018/7/23','2018/7/24','2018/7/25','2018/7/26','2018/7/27','2018/7/28','2018/7/29','2018/7/30','2018/7/31']
    hebei= [69,32,35,32,87,88,98,65,66,89,74]
    shanxi=[13,45,67,89,32,55,66,32,53,66,89]
    
    #折线图
    plt.plot(date,hebei,color='red',label='河北')
    plt.plot(date,shanxi,color='blue',label='山西')
    plt.xlabel('日期')
    plt.ylabel('车次')
    plt.title('车次表')
    plt.xticks(rotation=45) #闲转45度
    plt.legend()
    plt.show()
    
    #柱状图
    plt.bar(date,hebei,color='red',label='河北')
    plt.bar(date,shanxi,color='blue',label='山西')
    plt.xlabel('日期')
    plt.ylabel('车次')
    plt.title('车次表')
    plt.xticks(rotation=45) #闲转45度
    plt.legend()
    plt.show()
    
    #饼图
    number=[777,444]
    province=['河北','山西']
    colors=['red','blue']
    plt.pie(x=number,labels=province,colors=colors)
    plt.legend()
    plt.show()
  • 相关阅读:
    Font Awesome 中文网
    mobileselect学习
    JavaScript模块化
    webpack基本使用
    MVVM架构方式
    http-server开启测试服务器
    json-server模拟服务器API
    vue-router
    git的使用
    Vue生命周期
  • 原文地址:https://www.cnblogs.com/hzcjd/p/13263780.html
Copyright © 2011-2022 走看看