python中的matplotlib模块默认不支持中文的显示,中文会显示乱码,如下图的红框所示:

使用matplotlib_fname()会显示Matplotlib配置文件的保存位置,如下所示:

>>>import matplotlib
>>>matplotlib.matplotlib_fname()
>>>'D:\\Python\\Python36\\lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc'

打开该文件,找到如下代码:

#font.family : sans-serif
上面这一行设置了Matplotlib的默认字体,取消这一行前面的注释符号(#),并将后面的sans-serif修改为本地已有的中文字体,例如使用微软雅黑:

font.family : Microsoft YaHei

原文来自:https://blog.csdn.net/jacken123456/article/details/103092598

本文地址:https://www.linuxprobe.com/python-matplotlib-luanma.html编辑:问题终结者,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/