解决matplotlib中文乱码问题(Ubuntu16.04)
2017-09-06 22:59
786 查看
网上教程很多,但是折腾了好久才弄好。特此记录一下。
查看matplotlib配置文件位置
PS:因为之前安装了两个matplotlib的库。所以这里会有问题。
一个使用sudo apt-get install python-matplotlib安装,在root用户下。
一个使用pip install matplotlib普通用户安装。
后来使用 sudo apt-get remove python-matplotlib后,才能显示正常的matplotlib配置文件。
永久解决方法
首先将windwos中fonts目录下的simhei.ttf拷贝到/usr/share/matplotlib/mpl-data/fonts/ttf目录中
修改配置文件
去除这三列之前的‘#’
在font.sans-serif后添加,SimHei
删除~/.cache/matplotlib的缓冲
验证
新建python文件,输入以下内容
若出现如下图的中文字符,则说明更改成功。
最后附上simhei.ttf的链接
simhei.ttf
查看matplotlib配置文件位置
>>> import matplotlib >>> print matplotlib.matplotlib_fname() /usr/local/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
PS:因为之前安装了两个matplotlib的库。所以这里会有问题。
一个使用sudo apt-get install python-matplotlib安装,在root用户下。
一个使用pip install matplotlib普通用户安装。
后来使用 sudo apt-get remove python-matplotlib后,才能显示正常的matplotlib配置文件。
永久解决方法
首先将windwos中fonts目录下的simhei.ttf拷贝到/usr/share/matplotlib/mpl-data/fonts/ttf目录中
修改配置文件
去除这三列之前的‘#’
在font.sans-serif后添加,SimHei
``` #font.family : sans-serif #font.sans-serif : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif ... #axes.unicode_minus : False #解决负号'-'显示为方块的问题 ```
删除~/.cache/matplotlib的缓冲
验证
新建python文件,输入以下内容
# -*- coding:utf-8 -*- from matplotlib import pyplot as plt plt.title(u'显示中文') plt.show()
若出现如下图的中文字符,则说明更改成功。
最后附上simhei.ttf的链接
simhei.ttf
相关文章推荐
- Ubuntu16.04 matplotlib乱码问题解决办法(亲测可行)
- Ubuntu16.04 matplotlib 乱码问题解决办法
- ubuntu系统下matplotlib中文乱码问题的解决方法
- ubuntu16.04安装matplotlibm导致中文乱码的问题解决
- Ubuntu下matplotlib绘图中文乱码问题的解决
- 解决matplotlib中文乱码问题
- ubuntu系统下matplotlib中文乱码问题
- 真·matplotlib中文乱码问题·解决方法
- 彻底解决matplotlib中文乱码问题
- 解决matplotlib中文乱码问题(Windows)
- 解决matplotlib绘图中显示中文乱码的问题
- 解决matplotlib中文乱码问题
- Python 3下使用Matplotlib工具画图,中文显示乱码的问题解决(修改配置文件)
- 解决Windows系统下python利用matplotlib绘图时中文乱码的问题
- 彻底解决matplotlib中文乱码问题(转)
- 解决matplotlib中文乱码问题(Windows)
- 解决matplotlib中文乱码问题(Windows)
- 在matplotlib中,解决中文乱码问题
- 一次解决Matplotlib绘图中的中文乱码问题
- matplotlib解决中文乱码问题