解决matplotlib在图表中无法显示中文的问题

在进行matplotlib绘制图表的过程之中出现了如下报错

C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:64: UserWarning: Glyph 8722 (\N{MINUS SIGN}) missing from current font.
  self.figure.tight_layout()
C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py:65: UserWarning: Glyph 8722 (\N{MINUS SIGN}) missing from current font.
  FigureCanvasAgg.draw(self)

原因:matplotlib找不到中文字体

解决方法:在代码前段添加如下代码即可解决

plt.rcParams['font.sans-serif']=['SimHei'] #显示中文标签
plt.rcParams['axes.unicode_minus']=False

你可能感兴趣的:(bug报错,python)