Matplotlib 顯示中文

配置 .ttf 字型

Ubuntu: 放置於/usr/share/fonts/truetype/arphic

參考:台北黑體

刪除 Matplotlib 的 cache 使其重新生成

rm -rf ~/.cache/matplotlib/*

為 matplotlib 新增中文字體

 

import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['Taipei Sans TC Beta'] + matplotlib.rcParams['font.sans-serif']

查詢字體名稱

Ubuntu: fc-list :lang=zh

/usr/share/fonts/truetype/arphic/TaipeiSansTCBeta-Light.ttf: Taipei Sans TC Beta,Taipei Sans TC Beta Light:style=Light,Regular
/usr/share/fonts/truetype/arphic/TaipeiSansTCBeta-Regular.ttf: Taipei Sans TC Beta:style=Regular
/usr/share/fonts/truetype/arphic/TaipeiSansTCBeta-Bold.ttf: Taipei Sans TC Beta:style=Bold

Last Updated on 2024/10/21 by A1go

目錄
Bitnami