WIN7 matplotlib图例中文乱码(小方块)

参考资料:https://www.tuicool.com/articles/If2Efu


找到matplotlibrc文件

import matplotlib
matplotlib.matplotlib_fname() #将会获得matplotlib包所在文件夹 H:\\Anaconda3\\lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc


修改matplotlibrc文件

1、打开matplotlibrc文件

找到 #font.family         : sans-serif

删除#符号

2、找到#font.sans-serif     : Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

修改为font.sans-serif     : Microsoft YaHei ,Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

即去掉注释,并在配置值中添加 Microsoft YaHei

3、在C:\Windows\Fonts中找到msyh.ttf,即微软雅黑字体。将msyh.ttf复制到H:\Anaconda3\Lib\site-packages\matplotlib\mpl-data\fonts\ttf


重启python

猜你喜欢

转载自blog.csdn.net/yyy430/article/details/80078870