python之绘图的时候汉字乱码的问题

有时候,在用如下语句时,会出现乱码问题:

plt.xlabel('这是横坐标')
plt.ylable('这是纵坐标')

绘制出来的figure中汉字变成了小框框,这时候,可以用这个语句来消除这个烦人的error!

font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
plt.xlabel('这是横坐标', fontproperties=font)
plt.ylabel('这是纵坐标', fontproperties=font)

我爱你就像天上的太阳,太阳它将我照亮。--鲁迅

猜你喜欢

转载自blog.csdn.net/shangxiaqiusuo1/article/details/83048345