美文网首页
python3 | Matplotlib永久支持中文的设置方法

python3 | Matplotlib永久支持中文的设置方法

作者: 布莱特杨 | 来源:发表于2021-08-19 17:35 被阅读0次

    1 下载字体

    https://www.fontpalace.com/font-download/simhei/

    2 将字体复制到对应的ttf目录

    /.../lib/python3.8/site-packages/matplotlib/mpl-data/fonts/ttf

    3 修改matplotlibrc文件

    /.../python3.8/site-packages/matplotlib/mpl-data/matplotlibrc
    (1) 删除font.family前的‘#’号注释
    (2) 添加SimHei到font.sans-serif的冒号后面
    (3) 将axes.unicode_minus前的#号去掉,并将冒号后的值修改为False
    如下:

    font.family:  sans-serif
    ...
    font.sans-serif: SimHei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
    ...
    axes.unicode_minus: False
    

    4 删除缓存文件

    rm -rf ~/.cache/matplotlib

    布莱特杨
    2021-08-18 22:10

    相关文章

      网友评论

          本文标题:python3 | Matplotlib永久支持中文的设置方法

          本文链接:https://www.haomeiwen.com/subject/rokdpltx.html