用matplotlib画图时,给图像标题、横纵坐标轴的标签、图例显示中文名字

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)

plt.title(u"各等级的乘客年龄分布", fontproperties=font)
plt.xlabel(u"年龄", fontproperties=font)
plt.ylabel(u"密度", fontproperties=font)
plt.legend((u’头等舱’, u’2等舱’,u’3等舱’,),loc=‘best’, prop=font)

猜你喜欢

转载自blog.csdn.net/qq_25886325/article/details/90600672