線型圖:dom
#導包 import matplotlib.pyplot as plt #導入字體庫 from matplotlib.font_manager import FontProperties #設置本機字體 font = FontProperties(fname='C:/Windows/Fonts/simhei.ttf',size=15) #填充數據 # plt.plot(['2019-03-01','2019-03-02','2019-03-03'],[6,2,4]) #繪製方法 # plt.show() #定製數據 x1 = ['2019-03-01','2019-03-02','2019-03-03','2019-03-04','2019-03-05','2019-03-06'] y1 = [0,5,3,2,7,1] x2 = ['2019-03-01','2019-03-02','2019-03-03','2019-03-04','2019-03-05','2019-03-06'] y2 = [18,30,21,15,26,23] #填充數據 plt.plot(x1,y1,label='temperature') plt.plot(x1,y2,label='water') #設置標題 若是是漢字必須導入字體庫否則會識別不出 plt.title('溫溼度趨勢圖',FontProperties=font) #顯示圖例 plt.legend() #繪製 plt.show()
柱狀圖:字體
#導包 import matplotlib.pyplot as plt #設置數據 salary = [9000,10000,5000] group = ['beijing','shanghai','guangzhou'] #填充數據 plt.bar(group,salary) #設置標題 plt.title('salary/group') #繪製 plt.show()
散點圖:spa
import matplotlib.pyplot as plt #導包科學計算庫 import numpy as np #設置數據 plt.scatter(2,4) #繪製 # plt.show() #定義x軸數據 x = list(range(0,101)) y = [xvalue * np.random.rand() for xvalue in x] #填充數據 #s 點的大小和粗細 #c 顏色 plt.scatter(x,y,s=20,c='blue') #繪製 plt.show()