#導入相關包
from matplotlib import pyplot as plt import matplotlib from matplotlib import font_manager
#初始化數據 y1 = [1, 0, 2, 3, 5 ,6 ,8, 9, 8, 1, 2,1] y2 = [1, 1, 0, 3, 5, 8, 2, 7, 2, 5, 2,1] x = range(1,13) #建立畫布,設置畫布大小和分辨率
plt.figure(figsize=(20, 8),dpi=80)
#繪製曲線 plt.plot(x,y1,color='red',label='本身') plt.plot(x,y2,color='blue',label = '朋友') #設置x軸刻度
xtick_labels = ['{}月'.format(i) for i in x] my_font = myfont = font_manager.FontProperties(fname='C:\Windows\Fonts\FZSTK.TTF',size = 18) plt.xticks(x,xtick_labels,fontproperties=myfont) #繪製網格線and網格線透明度
plt.grid(alpha = 0.3) #添加圖例
plt.legend(prop=my_font,loc='upper right')#設置xlabel,ylabel和標題plot.xlabel('時間',fontproperties=myfont)plot.ylabel('顧客數',fontproperties=myfont)plot.title('店鋪時間點訪問顧客數',fontproperties=myfont,color='red')#plot.savefig('./ti.png')#保存爲圖片,若先調用plt.show()方法,對象將被銷燬保存圖片將是空白 plt.show()