解決matplotlib或seaborn的中文畫圖問題

matplotlib和seaborn畫圖默認中文不能顯示的問題

解決方案

指定字體庫
代碼以下所示python

from matplotlib.font_manager import FontProperties
import seaborn as sns
import matplotlib.pyplot as plt

#指定字體 windows的字體庫在下面所示路徑,裏面有不少字體庫

#也能夠在網上下載ttf字體文件,本身指定路徑
myfont=FontProperties(fname=r'C:\Windows\Fonts\SIMYOU.ttf',size=8)
sns.set(font=myfont.get_name())
plt.plot(range(10))
plt.title('測試中文')

如圖所示,就能夠顯示中文了
windows

相關文章
相關標籤/搜索