完美解决Pycharm中matplotlib画图中文乱码问题
作者:_Devil. 时间:2021-11-01 00:25:35
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 #用来正常显示负号
来源:https://blog.csdn.net/qq_40141862/article/details/112403269
标签:Pycharm,matplotlib,中文乱码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHPExcel冻结(锁定)表头的简单实现方法
2023-08-18 02:35:21
![](https://img.aspxhome.com/file/2023/9/55379_0s.jpg)
asp自动生成javascript检验函数
2009-01-21 19:40:00
ASP实现最简洁的多重查询的解决方案
2007-09-28 12:00:00
利用python numpy+matplotlib绘制股票k线图的方法
2022-12-16 07:21:52
![](https://img.aspxhome.com/file/2023/0/67880_0s.jpg)
Python文件操作的方法
2022-10-27 19:54:29
![](https://img.aspxhome.com/file/2023/8/107938_0s.jpg)
详解php中curl返回false的解决办法
2023-10-01 05:53:22
python将unicode和str互相转化的实现
2023-07-17 21:36:34
Python选课系统开发程序
2023-07-21 00:25:03
![](https://img.aspxhome.com/file/2023/3/70693_0s.png)
Asp WinHttp.WinHttpRequest.5.1 对象使用详解
2012-05-02 10:15:27
Python hashlib模块加密过程解析
2021-09-08 13:29:25
Python构建区块链的方法详解
2021-01-07 07:20:55
![](https://img.aspxhome.com/file/2023/5/99045_0s.png)
面向对象设计过程中必须遵守的相关准则
2009-01-08 15:52:00
Python处理文本换行符实例代码
2021-08-19 18:31:51
![](https://img.aspxhome.com/file/2023/5/67225_0s.png)
Go语言实现超时的三种方法实例
2023-06-22 18:32:43
matplotlib.pyplot画图并导出保存的实例
2022-10-02 13:32:26
python里读写excel等数据文件的6种常用方式(小结)
2021-04-09 08:11:52
关于Internet Explorer 8
2009-03-22 15:40:00
Python自定义进程池实例分析【生产者、消费者模型问题】
2023-05-20 12:20:02
Python无头爬虫下载文件的实现
2023-11-30 03:24:00
如何把数据从SQL Server导出到Access或Excel中去?
2009-11-02 20:26:00