data = pd.read_json(json.dumps(issue_dpl))
# set pic size
plt.figure(figsize=(13, 5))
sns.set_style('whitegrid', {'font.sans-serif': ['simhei', 'Arial']})
ax3 = sns.barplot(x=data['cls'], y=data['count'], data=data, ci=0)
ax3.set_title(u'问题分类统计')
ax3.set_xlabel(u'')
ax3.set_ylabel(u'')
plt.xticks(np.arange(len(cls_arr)) + 0.4 / 2, cls_arr, rotation=45)
sio = StringIO.StringIO()
savefig(sio, bbox_inches='tight', format='png')
savefig(‘test.png’, bbox_inches='tight', format='png') # tight强制显示全部,避免字体显示不全
plt.show()
cls count
0 不良质量 44
1 不正确校验 39
2 安全配置 32
3 信息泄露 24
4 权限控制 23
参考地址:https://www.cnblogs.com/gczr/p/6767175.html https://blog.csdn.net/qq_34264472/article/details/53814653
linux Tkinter导入报以下错解决:
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
>>>
KeyboardInterrupt
>>>
先看原版本python是否可以导入,如果可以的话,直接跳过安装tk等包,否则先后安装tk-devel,python-tk, tcl, tcl-devel等包,然后重新编译安装python,解决
linux系统画图报错解决:(TclError: no display name and no $DISPLAY environment variable)
参考:https://blog.csdn.net/qq_22194315/article/details/77984423
linux中文乱码解决:
Linux、Mac osx 系统中,出现 matplotlib 或 seaborn 绘图中有中文乱码的情形,可以考虑使用以下方式处理:
- 到 anaconda 的 matplotlib 中查看是否有 simhei.ttf 字体:
-
cd ~/anaconda3/lib/python3.5/site-packages/matplotlib/mpl-data/fonts/ttf
ls -al | grep simhei
- 如果没有,从 windows 中用 everything 搜索全局文件,找到 simhei.ttf,并将其上传到linux 的 matplotlib 的 fonts/ttf 文件夹
- 修改配置文件~/anaconda3/lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc 文件,
将该文件拷贝到.cache/matplotlib 目录下,并找到以下两行,改为如下:
-
-
font.family : sans-serif
font.sans-serif : simhei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
- (linux)删除~/.cache/matplotlib/目录下的 fonts cache list,
-
rm -r ~/.cache/matplotlib
- 代码设置 matplotlib 和 seaborn 的环境
-
import matplotlib as mpl
# mpl.rcParams['font.sans-serif'] = ['simhei']
# mpl.rcParams['font.serif'] = ['simhei']
import seaborn as sns
sns.set_style("darkgrid",{"font.sans-serif":['simhei','Droid Sans Fallback']})
参考:
|