尽管很卖力的写了中文要正确显示,
>>> plt.show() C:\Python27\lib\site-packages\matplotlib\font_manager.py:1297: UserWarning: find font: Font family [u'sans-serif'] not found. Falling back to DejaVu Sans (prop.get_family(), self.defaultFamily[fontext])) >>> plt.title(u'中文显示吧看好了') <matplotlib.text.Text object at 0x0000000009CB7780> >>> res[res['XH']>=28].groupby(res.TABLE_NAME).agg({'COUNT_JL':np.sum}).plot(kin d='bar',title=u'中文你正常显示吧求你了!!') <matplotlib.axes._subplots.AxesSubplot object at 0x0000000009D47160>
但show()出来的结果差强人意。 努力的方式不对,这是智力上的懒惰。(你在一条漆黑的街道丢了钥匙,却在隔壁街道找寻,只因为隔壁街道灯光透亮。--《人件》)
网上查找了几种方法,比较推荐的一种是,每次使用都灵活设置一下字体编码
#-*- coding: utf-8 -*- from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei'] mpl.rcParams['axes.unicode_minus'] = False t = arange(-4*pi, 4*pi, 0.01) y = sin(t)/t plt.plot(t, y) plt.title(u'钟形函数') plt.xlabel(u'时间') plt.ylabel(u'幅度') plt.show()
测试了一下,上面的办法可行。
使用此办法。输入
>>> res[res['XH']>=28].groupby(res.TABLE_NAME).agg({'COUNT_JL':np.sum}).plot(kin d='bar',title=u'啊哈哈哈')
plt.show()
起到中文字符显示设定作用的代码
#-*- coding: utf-8 -*- from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei'] mpl.rcParams['axes.unicode_minus'] = False