为什么我收到 UserWarning:Matplotlib 目前正在使用 ps,它是非 GUI 后端,因此无法显示图形

Sha*_*oon 3 python matplotlib

这不在jupyter笔记本中,所以这不是这个问题的重复,但我的代码是:

from gluoncv import model_zoo, data, utils
from matplotlib import pyplot as plt

...
plt.show()
Run Code Online (Sandbox Code Playgroud)

我收到的错误是:

/figure.py:445: UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure.
  % get_backend())
Run Code Online (Sandbox Code Playgroud)

我在https://repl.it/@shamoons/WelloffHarmfulMineral创建了一个 repl

如果重要的话,我使用的是 OS X。我需要做什么才能显示图像?

phi*_*hem 5

您可以使用

matplotlib.use("TkAgg")
Run Code Online (Sandbox Code Playgroud)

代替

matplotlib.use("PS")
Run Code Online (Sandbox Code Playgroud)

在 MacOS 上开发时。

请注意,导入应该在导入之前plt,如下所示:

import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
Run Code Online (Sandbox Code Playgroud)