matplotlib 显示中文

时间:2021-08-07 03:56:15
# --*-- coding: utf-8 --*--
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt font = FontProperties(fname=r"/usr/share/fonts/win/msyh.ttf", size=14)
fig = plt.figure(figsize=(6, 6)) x = [1, 2, 3, 4, 5, 6, 7, 8]
y = []
for i in x:
y.append(-(i * i) + i + 3) ax = fig.add_subplot(111)
ax.plot(x, y, label=u'我我问') plt.title(u'测试程序', fontproperties=font)
plt.xlabel(u'x轴', fontproperties=font)
plt.ylabel(u'y轴', fontproperties=font) plt.grid(True)
plt.legend(prop=font) # 要让lable也支持中文
plt.show()

http://hi.baidu.com/bithigher/item/b9ce6d85dc102adc98255fb7 感谢这篇文章