1. 程式人生 > >matplotlib圖示中文顯示

matplotlib圖示中文顯示

設定有fontproperties屬性的,還有prop屬性的

1,找到系統已安裝的字型

2,

from matplotlib.font_manager import FontProperties
#fname=r"(本地中文字型的路徑位置)",size=設定字型大小

 
font = FontProperties(fname=r"C:\\Windows\\Fonts\\STKAITI.TTF", size=14)

3,

plt.xlabel('性別', fontproperties=font)

plt.ylabel('人數', fontproperties=font)

或則沒有fontproperties屬性的

plt.legend((rect,), ('圖例',), prop=font)

然後設定的這些都可以正常的顯示了