Python自動化操作實現圖例繪制
折線圖,柱狀圖,餅圖用于數據展示,更直觀的分析數據。實現繪制的效果圖如下
代碼 很簡單,如下
import matplotlib.pyplot as pltplt.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()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
