简体   繁体   English

为什么得到用户警告:Matplotlib当前正在使用ps,这是非GUI后端,因此无法显示该图

[英]Why am I getting UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure

This is not in a jupyter notebook so this is not a duplicate of this question , but my code is: 这不在jupyter笔记本中,因此这不是此问题重复项 ,但是我的代码是:

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

...
plt.show()

The error I'm getting is: 我得到的错误是:

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

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

If it matters, I'm using OS X. What do I need to do to get the image to show? 如果有问题,我正在使用OSX。我需要做些什么才能显示图像?

matplotlib.use('PS') and plt.show() are mutually exclusive. matplotlib.use('PS')plt.show()是互斥的。 You need to decide: 您需要决定:

  • Do you want to show the figure on screen? 您要在屏幕上显示图形吗? Solution: Remove the line matplotlib.use('PS') . 解决方案:删除行matplotlib.use('PS')
  • Do you want to use the PS backend? 您要使用PS后端吗? This seems unlikely, because there is rarely a reason to set the backend to something non-interactive unless working on a server. 这似乎不太可能,因为除非在服务器上工作,否则几乎没有理由将后端设置为非交互式。 Anyways, solution: Replace plt.show() by plt.savefig("filname.ps") . 无论如何,解决方案:将plt.show()替换为plt.savefig("filname.ps")

You can use 您可以使用

matplotlib.use("TkAgg")

instead of 代替

matplotlib.use("PS")

when developing on MacOS. 在MacOS上进行开发时。

Please note that the import should be before importing plt , like this: 请注意,导入应在导入plt之前进行,如下所示:

import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户警告:Matplotlib 当前使用 agg,这是一个非 GUI 后端,因此无法显示图 - UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure 在一个源代码中,我输入它并得到: UserWarning:Matplotlib 当前正在使用 agg,这是一个非 GUI 后端,所以无法显示图 - In a source code, I typed it in and got: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure PyCharm Matplotlib "UserWarning: Matplotlib 当前正在使用 agg,这是一个非 GUI 后端,所以无法显示图。plt.show()" - PyCharm Matplotlib "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. plt.show()" “用户警告:Matplotlib 当前正在使用非 GUI 后端的 agg,因此无法显示图形。” 在 Pycharm 上用 pyplot 绘制图形时 - "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm RE: UserWarning: Matplotlib 目前正在使用 agg,它是一个非 GUI 后端,所以无法在 PyCharm 中显示 figure.plt.show() - RE: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.plt.show() in PyCharm UserWarning: Matplotlib 当前正在使用 agg,所以无法显示图 - UserWarning: Matplotlib is currently using agg, so cannot show the figure 当我在 jupyter notebook 中使用 matplotlib 时,它总是引发“matplotlib 当前正在使用非 GUI 后端”错误? - When I use matplotlib in jupyter notebook,it always raise “ matplotlib is currently using a non-GUI backend” error? 我不知道为什么我得到AttributeError - I cannot figure out why I am getting AttributeError 无法弄清楚为什么我收到UnboundLocalError - Cannot figure out why I am getting UnboundLocalError 读取多个文件,但找出我当前在哪个文件上 - read multiple files, but figure out which file I am currently on
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM