【Python】解決matplotlib圖例中文亂碼問題——win10版本

1. 找到matplotlib 配置文件:
import matplotlib
print(matplotlib.matplotlib_fname())
E:\software\python\anaconda\lib\site-packages\matplotlib\mpl-data\matplotlibrc


2. 編輯上述文件,uncomment the following 2 lines
font.family         : sans-serif
font.sans-serif     : DejaVu Sans, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif


3. http://font.chinaz.com/161111131720.htm 下載字體:msyh.ttf (微軟雅黑)
放在E:\software\python\anaconda\Lib\site-packages\matplotlib\mpl-data\fonts\ttf


4. 刪除.matplotlib/cache裏面的兩個緩存字體文件
file:///C:/Users/Administrator/.matplotlib/tex.cache
file:///C:/Users/Administrator/.matplotlib/fontList.json


5. 重啓Python


6. 代碼中添加plt.rcParams['font.sans-serif']=['Microsoft YaHei']

發佈了13 篇原創文章 · 獲贊 21 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章