Matplotlib 数字不显示减号 CMU Sans Serif

Matplotlib Figures Not Displaying Minus Sign CMU Sans Serif

几天前我买了一台新电脑并安装了最新版本的 anaconda,我正在尝试使用与之前相同的代码在我的另一台电脑上进行绘图。当我绘图时,无法使用 CMU Sans Serif 字体显示减号。它吐出以下错误

C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 8722 missing from current font.
  font.set_text(s, 0.0, flags=flags)
C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 8722 missing from current font.
  font.set_text(s, 0, flags=flags)

它还绘制了以下错误图。请参考颜色条的负号。

以下是我的代码:

plt.rcParams['font.sans-serif'] = "CMU Sans Serif"
plt.rcParams['font.family'] = "sans-serif"
plt.rcParams['mathtext.fontset'] = 'cm' 

# I can provide any x,y,z data here and every negative data reproduces the same error
plt.scatter(x,y,c=z,cmap='jet')
plt.colorbar()

如果我不包含 plt.rcParams['font.sans-serif'] = "CMU Sans Serif" 部分,它会正确显示负号,但它不是我目前需要的字体。我通过转到 Word 文档并使用这些字体中的任何一种输入负号进行检查,它们都可以正常工作,所以这似乎不是字体安装本身的问题。任何解决此问题的帮助或指导将不胜感激。在此先感谢您的任何帮助或建议。

我发现通过使用

matplotlib.rcParams['axes.unicode_minus'] = False

我可以在那个特定代码中解决这个问题。

如果您想永久解决此问题,请在 matplotlib rc file 中设置相应的参数。