天天看点

Legend-用python中的matplotlib.legend()函数显示图例(中文显示)

这个过程其实很简单,代码如下:

@SCOUTSONG
#其中x,y,z,v为变量,自己定义即可.
import matplotlib.pyplot as plt
from matplotlib import font_manager
my_font=font_manager.FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=30)   
plt.xlabel(u'X轴',fontproperties=my_font)   
plt.ylabel(u'Y轴',fontproperties=my_font)    
A,=plt.plot(x, y, label=u'第一条',color='blue') 
B,=plt.plot(x, z, label=u'第二条', color='red')  
C,=plt.plot(x, v, label=u'第三条', color='green') 
font1={'family':'SimHei', 
       'weight':'normal', 
       'size':30,}
legend=plt.legend(handles=[A, B, C], prop=font1) 
plt.show()
           

结果如图所示:

Legend-用python中的matplotlib.legend()函数显示图例(中文显示)

时间过的还是很快的,Fight for myself ! ! !