Colab中matplotlib包作图如何显示中文

首先导入中文系统文件

from google.colab import files
files.upload()
import matplotlib.pyplot as plt
import matplotlib as mpl

zhfont = mpl.font_manager.FontProperties(fname='chinese.simhei.ttf')
plt.figure()
plt.plot(range(10),range(10),label="你好啊")
plt.xlabel(u"x轴",fontproperties=zhfont)
plt.ylabel(u"y轴",fontproperties=zhfont)
plt.legend()
plt.show()

结果如下:
Colab中matplotlib包作图如何显示中文_第1张图片

至于plt.legend()里头的中文设置还有待考究

你可能感兴趣的:(python)