Matplotlib 显示中文

# coding=utf-8
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = ['sans-serif'] # 在我的 notebook 里,要设置下面两行才能显示中文
plt.rcParams['font.sans-serif'] = ['SimHei'] # 如果是在 PyCharm 里,只要下面一行,上面的一行可以删除

x = list(range(1,6))
y = [x ** 2 for x in range(1,6) ]
plt.plot(x,y,linewidth=4)
plt.title("这是表头",fontsize=24)
plt.xlabel('x',fontsize=14)
plt.ylabel('y',fontsize =20)
plt.show()

 

Time Will Tell
原文地址:https://www.cnblogs.com/wangzaixue/p/13632361.html