【问题标题】:Matplotlib Figures Not Displaying Minus Sign CMU Sans SerifMatplotlib 数字不显示减号 CMU 无衬线
【发布时间】:2019-11-17 02:08:34
【问题描述】:

几天前我买了一台新电脑并安装了最新版本的 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 文档并使用这些字体中的任何一种输入负号进行检查,它们都可以正常工作,因此字体安装本身似乎不是问题。任何有关解决此问题的帮助或指导将不胜感激。提前感谢您的任何帮助或建议。

【问题讨论】:

    标签: python matplotlib fonts anaconda


    【解决方案1】:

    我发现通过使用

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-24
      • 2014-01-09
      • 2019-02-18
      • 2014-01-10
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      相关资源
      最近更新 更多