[問題] matplotlib 下怎麼使用times new roman?

看板Python作者 (pete)時間2年前 (2022/03/15 16:28), 編輯推噓2(208)
留言10則, 3人參與, 2年前最新討論串1/1
我的matplotlib版本是 3.5.1 我在畫圖的時候 想把字型設定成 Times new Roman 但是一直有錯誤訊息 findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans. 有人知道要怎麼在matplotlib下去安裝Times New Roman字型嗎? 這問題我google搜尋了一陣子 似乎一直找不到解答 所以才來版上詢問一下版友意見 萬分感謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.117.32.17 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1647332933.A.880.html

03/15 16:37, 2年前 , 1F
plt.rcParams["font.family"] = "Times New Roman"
03/15 16:37, 1F

03/15 16:37, 2年前 , 2F
你是這樣設定嗎?
03/15 16:37, 2F

03/15 16:50, 2年前 , 3F
先移除matplotlib font cache試試看吧
03/15 16:50, 3F

03/15 16:51, 2年前 , 4F
import matplotlib as mpl; mpl.get_cachedir()
03/15 16:51, 4F

03/15 16:52, 2年前 , 5F
把找到的cache資料夾刪掉,試看看
03/15 16:52, 5F

03/15 17:08, 2年前 , 6F
找到解決方法了
03/15 17:08, 6F

03/15 17:08, 2年前 , 7F
import matplotlib.pyplot as plt
03/15 17:08, 7F

03/15 17:08, 2年前 , 8F
plt.rcParams["font.family"] = "serif"
03/15 17:08, 8F

03/15 17:09, 2年前 , 9F
plt.rcParams['font.serif'] = ['Times New Roman'] + p
03/15 17:09, 9F

03/15 17:09, 2年前 , 10F
plt.rcParams['font.serif']
03/15 17:09, 10F
文章代碼(AID): #1YC4v5Y0 (Python)