import matplotlib print(matplotlib.matplotlib_fname())
以个人为例子,输出为css
C:\Users\adobe\app\anaconda3\lib\site-packages\matplotlib\mpl-data\matplotlibrc
因此说,以我使用的anaconda为例子,它在lib\site-packages\matplotlib\mpl-data\matplotlibrc
文件夹下面.
进入fonts\ttf
目录,把第一步下载的msyh.ttf放到该目录下面python
matplotlibrc
文件使用任何一个文件编辑器(推荐vscode),修改该文件,经过ctrl+f
搜索找到git
#axes.unicode_minus : True ## use unicode for the minus symbol #font.family : sans-serif #font.sans-serif : DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
分别修改成如下三行github
axes.unicode_minus : False ## use unicode for the minus symbol font.family : Microsoft YaHei font.sans-serif : Microsoft YaHei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
解释:缓存
使用下面的代码,获取缓存文件夹.app
import matplotlib print(matplotlib.get_cachedir())
个人输出为编辑器
C:\Users\adobe\.matplotlib
因此,通常在用户目录的matplotlib
,删除该目录下的全部文件测试
重启Python便可(意思是关闭全部正在运行的Python窗口,而后从新打开,要否则没法生效)字体
使用以下的简单代码进行测试spa
# coding:utf-8 import matplotlib.pyplot as plt plt.plot((1,2,3),(4,3,-1)) plt.xlabel(u'横坐标') # python3 能够不用u,已是默认了 plt.ylabel(u'纵坐标') plt.show()
