seaborn(matplotlib)畫圖,linux系統中文亂碼等問題解決

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導入報如下錯解決:html

 

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,解決python

linux系統畫圖報錯解決:(TclError: no display name and no $DISPLAY environment variable)linux

 

參考:https://blog.csdn.net/qq_22194315/article/details/77984423

 

  

 

 

linux中文亂碼解決:git

Linux、Mac osx 系統中,出現 matplotlib 或 seaborn 繪圖中有中文亂碼的情形,能夠考慮使用如下方式處理:
  1. 到 anaconda 的 matplotlib 中查看是否有 simhei.ttf 字體:
    1. cd ~/anaconda3/lib/python3.5/site-packages/matplotlib/mpl-data/fonts/ttf
      ls -al | grep simhei 
  2. 若是沒有,從 windows 中用 everything 搜索全局文件,找到 simhei.ttf,並將其上傳到linux 的 matplotlib 的 fonts/ttf 文件夾
  3. 修改配置文件~/anaconda3/lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc 文件,
  4. 將該文件拷貝到.cache/matplotlib 目錄下,並找到如下兩行,改成以下:
    1.   
      font.family         : sans-serif
      font.sans-serif     : simhei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

       

  5. (linux)刪除~/.cache/matplotlib/目錄下的 fonts cache list, 
    1. rm -r ~/.cache/matplotlib
  6. 代碼設置 matplotlib 和 seaborn 的環境
    1.   
      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']})

       

 
參考:
相關文章
相關標籤/搜索