matplotlib使用中文字型

2021-10-02 19:25:14 字數 437 閱讀 1937

matplotlib中本身是不支援中文的(utf-8都不行嗎),但是我們可以通過一定的方法進行解決

from matplotlib import font_manager

# fname 指定為系統中支援中文的字型

my_font = font_manager.fontproperties(fname=r"c:\windows\fonts\msyhl.ttc"

)# 呼叫的時候指定 fontproperties即可

plt.title(

"圖形影象"

, fontproperties=my_font)

但是在plt.legend中需要使用prop

plt.legend(prop=my_font)

ubuntu下matplotlib中文字型的設定

置方法主要參考中的第一種方法,第二種方法在ubuntu中怎麼設定都沒有用。如果有人在ubuntu 15.04成功使用第二種方法解決了,還請不吝賜教傳送郵件 因此,安裝步驟如下 1.確認你ubuntu系統環境下擁有的中文字庫案 fc list lang zh 命令輸出如下 usr share font...

matplotlib顯示中文字型

參考這篇就夠了 為 locate b mpl data sudo cp 源路徑 simhei.ttf 目的路徑 simhei.ttf 新安裝的字型 matplotlib 一時不能找到,字元會不顯示.需要更新字型列表快取。先刪除.cd cache matplotlib rm rf matplotlib...

matplotlib設定中文字型的方法

為什麼無法顯示中文 matplotlib預設不支援中文字元,因為預設的英文本型無法顯示漢字 檢視linux mac下面支援的字型 fc list 檢視支援的字型 fc list lang zh 檢視支援的中文 冒號前面有空格 例如 my font font manager.fontpropertie...