matplotlib--------簡單的折線圖之一圖多線

j

 

 

 

就是連個y值一個x值

import matplotlib.pyplot as plt
from  matplotlib import font_manager
import random
x= range(1,27,2)
y1 = [random.randint(1,30) for i in x]
y2 = [random.randint(1,30) for i in x]

font_manager = font_manager.FontProperties(fname = 'C:/Windows/Fonts/simsun.ttc',size = 18)


plt.figure(figsize=(20,8),dpi = 80)
plt.plot(x,y1,color = 'r',label = 'y1')
plt.plot(x,y2,color = 'y',label = 'y2')
plt.legend(prop = font_manager,loc = 'upper right') #在右上角生成圖例,loc:lower left、center left、upper center

#注意的是想要有圖例,就必須在plt.plot()中設置他的label值,這一塊的中文顯示用的是prop不是fontproperties
plt.show()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章