zoukankan      html  css  js  c++  java
  • 解决Ubuntu 16.04 环境下Python 无法显示中文的问题

    一.下载中文字体(https://pan.baidu.com/s/1EqabwENMxR2WJrHfKvyrIw 这里下载多是SImhei字体)

    安装字体:
    解压:unzip SimHei.zip
    拷贝字体到 usr/share/fonts 下(记得切换到.ttf的目录下面)

    sudo cp ./SimHei.ttf /usr/share/fonts/SimHei.ttf

    二. 查找matplotlib的配置目录

    python 
    import matplotlib
    print(matplotlib.matplotlib_fname())

    结果如下图所示

    三:更改matplotlib配置

    sudo gedit /home/huster/anaconda3/lib/python3.6/site-packages/matplotlib/mpl-data/matplotlibrc

    重点修以下三个地方(对应多注释#要去掉):

    1.font.family : sans-serif

    2.font.sans-serif: 这个字段要加上下载的中文字体名字,笔者使用多是Simhei,那么在后面字段的段首加上 Simhei

    3.axes.unicode_minus : False

    四:删除matplotlib字体缓存

    python
    import matplotlib 
    print(matplotlib.get_cachedir())

    找到对应对应的缓存目录,然后rm该目录下的fontList.json文件

    sudo rm /home/huster/.cache/matplotlib/fontList.json 
  • 相关阅读:
    SpringBoot学习历程
    日期和时间库Joda Time
    apache commons validator
    apache commons fileupload
    apache commons io
    apache commons compress
    apache commons codec
    apache commons email
    Http协议介绍
    Java原生Socket API
  • 原文地址:https://www.cnblogs.com/z1141000271/p/11226321.html
Copyright © 2011-2022 走看看