Python 中文乱码matplotlib乱码 (Windows)

来源:互联网 发布:林瀚的爷爷 知乎 编辑:程序博客网 时间:2024/05/29 16:51

Python解决matplotlib中文乱码问题(Windows)

matplotlib是Python著名的绘图库,默认并不支持中文显示,因此在不经过修改的情况下,无法正确显示中文。本文将介绍如何解决这一问题的方法。



1.修改matplotlibrc文件
进入Python安装目录下的Lib\site-packages\matplotlib\mpl-data目录,打开matplotlibrc文件,删除font.family和font.sans-serif两行前的#,并在font.sans-serif后添加微软雅黑字体(Microsoft YaHei),代码如下:
font.family         : sans-seriffont.sans-serif     : Microsoft YaHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

2.代码中别忘了unicode编码


转载自http://www.pythoner.com/200.html
0 0
原创粉丝点击