Skip to content

Instantly share code, notes, and snippets.

@geminixiang
Last active November 20, 2021 08:08
Show Gist options
  • Save geminixiang/b76f403a94e148746e28ac26598da515 to your computer and use it in GitHub Desktop.
Save geminixiang/b76f403a94e148746e28ac26598da515 to your computer and use it in GitHub Desktop.
Colab 中 matplotlib 顯示中文問題[快速解決]
# 下載台北黑體
!wget -O TaipeiSansTCBeta-Regular.ttf https://drive.google.com/uc?id=1eGAsTN1HBpJAkeVM57_C7ccp7hbgSz3_&export=download
import matplotlib as mpl
from matplotlib.font_manager import fontManager
# 修改字體設定
fontManager.addfont('TaipeiSansTCBeta-Regular.ttf')
mpl.rc('font', family='Taipei Sans TC Beta')
# 簡單測試
import matplotlib.pyplot as plt
plt.plot((10,20,30),(400,500,600))
plt.title("標題")
plt.ylabel("y軸")
plt.xlabel("x軸")
plt.show()