完美解决Pycharm中matplotlib画图中文乱码问题
程序员文章站
2022-06-28 11:37:08
matplotlibmatplotlib 是python中类似 matlab 的绘图工具,熟悉 matlab 也可以很快的上手 matplotlib。这篇文章给大家介绍pycharm matplotl...
matplotlib
matplotlib 是python中类似 matlab 的绘图工具,熟悉 matlab 也可以很快的上手 matplotlib。
这篇文章给大家介绍pycharm matplotlib画图中文乱码的问题及解决方法,本文给大家介绍的非常详细,一起看看吧!
我用的macos系统,不过windows也大同小异
首先去下载simhei字体:
https://github.com/stellarcn/scp_zh/blob/master/fonts/simhei.ttf
然后直接双击安装;
将下载的simhei.ttf移动到你的matplotlib/mpl-data/fonts/ttf/下,路径全称可在pycharm里使用下面的代码打印出来,我的是/library/python/3.8/site-packages/matplotlib/mpl-data/matplotlibrc/mpl-data/fonts/ttf/
import matplotlib path = matplotlib.matplotlib_fname() print(path)
然后去编辑/mpl-data/下的matplotlibrc,修改以下内容(去掉前面的#号,第三行修改为false)
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,#作用就是解决负号'-'显示为方块的问题
然后去pycharm或者python终端里面执行以下命令
from matplotlib.font_manager import _rebuild _rebuild()
最后在你要使用matplotlib画图的代码中加入如下两句
plt.rcparams['font.sans-serif']=['simhei'] #用来正常显示中文标签 plt.rcparams['axes.unicode_minus']=false #用来正常显示负号
到此这篇关于完美解决pycharm中matplotlib画图中文乱码问题的文章就介绍到这了,更多相关pycharm matplotlib画图中文乱码内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
推荐阅读
-
关于Cookie中带有中文乱码报错的问题解决
-
jquery.ajax的url中传递中文乱码问题的解决方法
-
解决Mysql5.7中文乱码的问题
-
跨浏览器PHP下载文件名中的中文乱码问题解决方法
-
解决URL地址中的中文乱码问题的办法
-
jsp中 ajax的get请求的中文乱码问题的解决方法
-
php中强制下载文件的代码(解决了IE下中文文件名乱码问题)
-
解决Python pandas plot输出图形中显示中文乱码问题
-
解决python3中的requests解析中文页面出现乱码问题
-
mysql命令框中向表中插入中文字符,在可视化工具MySQL Workbeach或phpMyAdmin中不显示或显示乱码的问题解决