在做可視化數(shù)據(jù)的時候录粱,餅圖出現(xiàn)了中文亂碼的情況腻格,網(wǎng)上有很多解決的辦法都沒有成功,最后自己添加了一個中文系統(tǒng)字體解決啥繁。
- 系統(tǒng)Ubuntu17.04
- python3.5
- matplotlib
普遍方法:
- 修改matplotlib配置文件菜职,文件位置自己查找:
sudo locate matplotlibrc
我的在這里:~/.local/lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc
- 找到如下font.family等改為如下,simhei.ttf為下載的中文字體旗闽。
#font.family : serif
font.serif : simhei.ttf
font.sans-serif : simhei.ttf
- 把字體放入文件夾:
~/.local/lib/python3.5/site-packages/matplotlib/mpl-data/fonts/ttf
- 在代碼中添加
plt.rcParams['font.sans-serif'] = ['simhei']
plt.rcParams['axes.unicode_minus'] = False
我的方法:
- 下載一個中文字體
- 放入系統(tǒng)文件夾
/usr/share/fonts/truetype/arphic
里面任意一個文件夾都可以酬核。