# 使用动漫风格
from matplotlib import pyplot as plt
plt.xkcd()
plt.figure(figsize=(16,10),dpi=100)
plt.rcParams['font.sans-serif']=['Microsoft YaHei'] # 使用微软雅黑的字体
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,'r^--',label='票房与票价')
plt.plot(bo,persons,'g*-',label='票房与人次')
plt.plot(bo,points,color='blue',marker='o',markersize=10,label='票房与评价')
plt.legend() # 显示标签
plt.xlabel('票房') # 横坐标轴标题
plt.ylabel('行情') # 纵坐标轴标题
plt.grid()
plt.savefig("cnbotop5_300.png")
plt.show()
Problem: As shown in the figure below, in time we used the Microsoft Yahei effect, but still cannot display Chinese fonts
Solution: Just add the following line of code:
plt.rcParams.update({
'font.family': "Microsoft YaHei"})
Microsoft YaHei
It is the Microsoft Yahei that comes with the computer system: