Linux解决matplotlib绘图中文字体乱码 | 您所在的位置:网站首页 › windows粘贴到linux › Linux解决matplotlib绘图中文字体乱码 |
输入Python代码: import matplotlib matplotlib.matplotlib_fname()输出: /root/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc首先查看系统内的中文字体,终端输入,查看是否存在相关字体: 如果没有,则可以从本地copy一份simhei.ttf文件到服务器,本地路径C:\Windows\Fonts; 上传到服务器的文件夹,在 /usr/share/fonts 路径下创建存放此字体的文件夹my_fonts,并下载的ttf文件复制到my_fonts中,具体参考我的博客:(26条消息) Linux安装黑体字体_小关不摆烂的博客-CSDN博客 然后修改matplotlibrc文件配置,进入到文件路径,,取消以下几行的注释,删除#号,改好之后esc退出,英文状态下:wq保存退出: font.family : sans-serif font.sans-serif : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif,WenQuanYi Zen Hei Mono axes.unicode_minus : False #这里要把True改为False,作用就是解决负号'-'显示为方块的问题将配置好的ttf字体复制一份到matplotlib的字体文件夹内: /root/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf此时字体已经存在于服务器,配置改了之后不会生效,需要在python内重新加载,即: from matplotlib.font_manager import _rebuild _rebuild() #reload一下 |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |