zoukankan      html  css  js  c++  java
  • Linux中matplotlib 中文显示问题解决

    1.下载下载中文 arial unicode ms 字体到 /home 目录

    2. 拷贝字体到 usr/share/fonts 下:

    • sudo cp ~/arial unicode ms.ttf /usr/share/fonts/arial unicode ms.ttf

    3. 修改配置文件,运行下列代码查看配置文件位置

    • import matplotlib
      print(matplotlib.matplotlib_fname()) #输出配置文件位置
      # eg:/home/python/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc

    进入到上述找到的配置文件中,修改下面两项

    sudo vim /home/python/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
    # 打开这一行注释
    font.family         : sans-serif        
    # 在原有字体之前,新增我们刚下载的中文字体 arial unicode ms
    font.sans-serif     : arial unicode ms, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

     4. 这一步骤最重要!为matplotlib增加中文字体.将下载的arial unicode ms.ttf字体文件复制一份到步骤2找到的配置文件的同级文件夹fonts中:

    sudo cp ~/arial unicode ms.ttf /home/python/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/arial unicode ms.ttf

     5. 清除本地matplotlib中的缓存

    • rm -rf ~/.cache/matplotlib

    现在就可以重新画图,查看中文效果了。

    <人追求理想之时,便是坠入孤独之际.> By 史泰龙
  • 相关阅读:
    羊车门悖论
    python--程序语言中的我行我素者
    最大流isap
    约瑟夫环问题
    CF 916 一言题解
    ZJOI2006 书架
    板子
    windows激活流程
    Ant Design 坑
    js+jQuery判断一个点是否在多边形中
  • 原文地址:https://www.cnblogs.com/jason-Gan/p/10712942.html
Copyright © 2011-2022 走看看