1. 程式人生 > 其它 >【Linux CentOS系統】Matplotlib不顯示Times New Roman

【Linux CentOS系統】Matplotlib不顯示Times New Roman

CentOS系統是沒有Times New Roman字型的。(其他字型類似操作)

步驟

  1. 把本地電腦裡C:\windows\fonts中的Time New Roman資料夾/4個檔案拷貝到CentOS系統中的/usr/share/fonts目錄下。
    在這裡插入圖片描述
    (我不確定是把整個資料夾拷過來,還是把4個檔案直接放進去,我都試了一下,不知道是哪個成功的。)
  2. 執行下面三條命令重新整理字型快取
mkfontscale
mkfontdir
fc-cache -fv

可以執行“fc-list”來檢視安裝了那些字型(看每一個小段落前面的那加個英文即可)

  1. 刪除matplotlib的快取
rm ~/.cache/matplotlib -rf
  1. 重啟作業系統
Reboot
  1. 開啟Matplotlib的python檔案,操作如下
import matplotlib
plt.rc('font',family='Times New Roman')
plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams['font.size'] = 12

font1 = {'family': 'Times New Roman',
'weight': 'normal',
'size': 12}
cbar.ax.set_ylabel(cbarlabel, font1, rotation =
-90, va = "bottom")

參考

https://www.cnblogs.com/xiaodiejinghong/p/4013454.html
https://www.cnblogs.com/shenchuguimo/p/13803901.html