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()
![](http://static.javashuo.com/static/loading.gif)