matplotlib-折線圖
阿新 • • 發佈:2018-10-29
rop true pytho sof ima 技術 分享圖片 port eight
1、plot繪制折線圖
from matplotlib import pyplot as plt x = range(2, 26, 2) y = [15, 13, 14.5, 17, 20, 25, 26, 26, 27, 22, 18, 15] # 設置圖片大小 plt.figure(figsize=(20, 8), dpi=180) # 繪制圖形,plot折線圖 plt.plot(x, y) # 保存圖形 plt.savefig("14.png") # 展示圖形 plt.show()
2、plot圖片的相關設置
from matplotlib import pyplot as plt x = range(2, 26, 2) y = [15, 13, 14.5, 17, 20, 25, 26, 26, 27, 22, 18, 15] # 設置圖片大小 plt.figure(figsize=(20, 8), dpi=80) # 繪制圖形,plot折線圖 plt.plot(x, y) # 設置x軸的刻度 plt.xticks(range(0,25)) # 設置y軸的刻度 max_y=max(y) min_y=min(y) yticks_labels=list(range(min_y,max_y+1))[::2] plt.yticks(yticks_labels)
3、plot相關設置2
import matplotlib from matplotlib import pyplot as plt import random from matplotlib import font_manager # 設置局部字體 my_font = font_manager.FontProperties(fname="C:\Windows\Fonts\STSONG.TTF") # 設置全局字體 # fc-list查看字體 font = {‘family‘: ‘Microsoft Yahei‘, ‘weight‘: ‘bold‘, } matplotlib.rc("font", **font) x = range(120) y = [random.randint(20, 35) for i in range(120)] # 圖大小 plt.figure(figsize=(20, 8), dpi=80) # 繪制折線圖 plt.plot(x, y) # x軸線刻度 _xticks_labels = ["10時{}分".format(i) for i in range(1, 61)] _xticks_labels += ["11時{}分".format(i) for i in range(1, 61)] # print(_xticks_labels) # plt.xticks(list(x)[::10],_xticks_labels[::10],rotation=30,fontproperties=my_font) plt.xticks(list(x)[::10], _xticks_labels[::10], rotation=30) plt.show()
matplotlib-折線圖