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']})
-
參考:
- https://github.com/mwaskom/seaborn/issues/1009
- http://www.th7.cn/Program/Python/201704/1156781.shtml
- https://www.jianshu.com/p/b76481530472