matplotlib绘图中文出现乱码

在ipython notebook中,我们使用matplotlib进行绘图的时候,中文会无法显示。如图
乱码图片
这是因为matplotlib默认字体不支持汉字,所以需要修改为SimHei字体,代码如下

from pylab import mpl 
mpl.rcParams['font.sans-serif']=['SimHei']   # 修改为中文字体
data.house_position.value_counts().plot(kind='bar')

在这里插入图片描述
这样就可以正常显示了。

猜你喜欢

转载自blog.csdn.net/weixin_36637463/article/details/87628991