matplotlib绘图 不显示中文 (解决方法)

问题:用matplotlib绘图时却不显示中文,而是框框。

解决方法:

1. 输入以下代码:

import matplotlib    
print(matplotlib.matplotlib_fname())

查看 C:\Users\...\Python\Python38\site-packages\matplotlib\mpl-data\fonts\tff里是否有相关的中文字体。

2. 如果没有就下载一个,(30天有效),将其解压至tff文件中

3. 打开C:\Users\...\Python\Python38\site-packages\matplotlib\mpl-data\matplotlibrc文件。修改以下:

 font.family         : sans-serif   
 # 去掉前面的#     
 font.sans-serif     : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif  
 # 去掉前面的#,并在冒号后面添加SimHei
 axes.unicode_minus  : False
 # 去掉前面的#,并将True改为False

4.保存,并关闭重启,应该就没问题了。


 参考链接:

Mac python matplotlib Glyph xxxxx missing from current font的解决方案

猜你喜欢

转载自blog.csdn.net/baidu_30506559/article/details/122277715