zoukankan      html  css  js  c++  java
  • matplotlib中文乱码

    matplotlib绘图时,title、xlabel、ylabel、label中文乱码。执行下面4步解决中文乱码的问题。(无论是本地,还是Linux服务器,Mac,还是Windows都是这个步骤)

    1、下载字体SimHei.tff

    2、将下载的字体拷贝matplotlib字体路径tff下

    查看配置路径

    1 import matplotlib
    2 print(matplotlib.matplotlib_fname())
    3 
    4 # 运行结果
    5 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/mpl-data/matplotlibrc

    拷贝字体

    1 cp ....../SimHei.ttf /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/mpl-data/fonts/ttf

    3、修改配置文件matplotlibrc文件。

    下面三项前面的#号去掉。第二项添加字体SimHei,第三项改为False

    1 font.family         : sans-serif 
    2 ...
    3 font.sans-serif     : SimHei, .........
    4 ...
    5 axes.unicode_minus  : False # use unicode for the minus symbol

    4、修改了配置文件,需要在代码中添加如下两行,重启文件运行就可以显示中文了

    1 from matplotlib.font_manager import _rebuild
    2 _rebuild()
    分享促进成长
  • 相关阅读:
    nginx转发域名小记
    简化kubernetes应用部署工具之Helm应用部署
    docker-compose的使用
    使用二进制包安装k8s
    搭建k8s(一)
    linux环境下安装使用selenium Chrome
    常用User-Agent大全
    缓存之Memcache
    git-commit Angular规范
    Kubernetes介绍及基本概念
  • 原文地址:https://www.cnblogs.com/hpzyang/p/14517193.html
Copyright © 2011-2022 走看看