当然,你没有搞错。真的,matplotlib在没有设置之前是不支持中文的输出,原因是没有载入中文字体的相关包,(对我这种英语极差的人极不友好)
解决的话,这里给windows系统的解决方法(mac的话,等我有内存去下载虚拟机的时候,在更新吧)
你可以先去c盘查看电脑中已经下载的字体,就直接在搜索中打入font,找到你需要使用的中文字体的地址
举一个简单的例子,输出标题:
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
plt.title(“标题”, fontproperties=font)
plt.show()
还有一种方法:
plt.rcParams[“font.sans-serif”]=[“SimHei”]
plt.rcParams[“axes.unicode_minus”]=False
在你的代码前面加入这两句。
大概就这样: