1. 程式人生 > >Win10下Matplotlib圖例中文亂碼解決

Win10下Matplotlib圖例中文亂碼解決

  • 系統:Win10
  • Python版本:3.6

第一步

找到matplotlib 配置檔案:

import matplotlib 
print(matplotlib.matplotlib_fname()) 
D:\Program Files\Python36\Lib\site-packages\matplotlib\mpl-data\matplotlibrc

第二步

然後將matplotlibrc檔案中的

#font.family: sans-serif

去掉註釋,修改為

font.family: Microsoft YaHei

第三步

下載字型:msyh.ttf (微軟雅黑)放在matplotlib 字型資料夾下:

D:\Program Files\Python36\Lib\site-packages\matplotlib\mpl-data\fonts\ttf

第四步

刪除.matplotlib/cache裡面的兩個快取字型檔案C:\Users\你的使用者名稱\.matplotlib

tex.cache
fontList.json

第五步

重啟Python