查看當前系統JupyterLab支持的所有字體
from matplotlib.font_manager import FontManager
mpl_fonts = set(f.name for f in FontManager().ttflist)
print('all font list get from matplotlib.font_manager:')
for f in sorted(mpl_fonts):
print('\t' + f)
打印結果如下:
選擇一款中文字體即可,這里我選擇的是蘋果的冬青黑體:"Hiragino Sans GB",windows用戶可以選擇黑體(SimHei)
刪除緩存文件
Mac:
-
cd ~/.matplotlib rm -r *
Windows:
-
進入到自己的用戶目錄文件夾下,在資源管理器的“查看”選項卡中勾選“顯示隱藏文件及目錄”即可看到
.matplotlib
文件夾,或者直接在資源管理器的路徑欄中在路徑后面手動輸入.matplotlib
后回車即可進入該文件夾 -
然后把該文件夾內的資源刪除即可。
修改matplotlibrc配置文件
Mac:
-
輸入
vim ~/.matplotlib/matplotlibrc
:然后將文件內容修改為:
font.family : sans-serif font.sans-serif : Hiragino Sans GB axes.unicode_minus : False
font.sans-serif
后面改為自己選擇的字體即可。
Win:
- 在
.matplotlib
文件夾中新建matplotlibrc文件,把上面內容粘貼進去后.txt
后綴名刪掉即可。
重啟JupyterLab內核
接下來重啟一下JupyterLab內核即可看到效果。