
1、问题现象
在colab中使用matplotlib绘图时,对中文字符不支持,导致出现方块
import matplotlib.pyplot as plt
plt.xlabel(u'词语')
plt.ylabel(u'特征重要度')
plt.xticks(rotation=270)
plt.bar(imp_plot['name'],imp_plot['imp'])

2、问题原因
- colab的虚拟机ubuntu操作系统没有支持中文的字体,通过!fc-list :lang=zh命令执行,发现结果为空;
- matplotlib配置文件没有支持中文的字体。
3、解决措施
- 从网上下载一个支持中文的字体到系统字体目录:
!wget -O /usr/share/fonts/truetype/liberation/simhei.ttf "https://www.wfonts.com/download/data/2014/06/01/simhei/chinese.simhe