查来查去还是以下方法简单粗暴,并且容易迁移到别的机器上:
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
def chinese_font():
return FontProperties(fname='/System/Library/Fonts/PingFang.ttc',size=15) # 系统字体路径,此处是mac的
plt.title(u'乘客等级分布', fontproperties=chinese_font()) #每一行都要添加,是不是很麻烦?
plt.ylabel(u'人数', fontproperties=chinese_font())
plt.legend((u'头等舱',u'二等舱',u'三等舱',),loc='best',prop=chinese_font())
plt.show()