【问题标题】:Using ginput in my code returns the error: matplotlib is currently using a non-GUI backend [duplicate]在我的代码中使用 ginput 返回错误:matplotlib 当前正在使用非 GUI 后端 [重复]
【发布时间】:2019-07-01 11:01:55
【问题描述】:

我试图弄清楚 ginput(3) 在这段代码中是如何工作的,但是当我运行它时,它返回一个 UserWarning 说:“matplotlib 当前正在使用非 GUI 后端,”

请帮我解决这个问题。

from PIL import Image
from pylab import *
im = array(Image.open('empire.jpg'))
imshow(im)
print ('Please click 3 points')
x = ginput(3)
print ('you clicked:',x)
show()

用户警告:matplotlib 当前使用非 GUI 后端,因此无法显示“matplotlib 当前使用非 GUI 后端”的图形

【问题讨论】:

  • 这可以从字面上理解。 Matplotlib 使用非 GUI backend。请参阅有关如何更改后端的链接。
  • @ImportanceOfBeingErnest 那么可以做些什么来消除我面临的这个警告?
  • 按照链接中的说明设置不同的后端。
  • @ImportanceOfBeingErnest 完成了这项工作,谢谢!

标签: python matplotlib ginput


【解决方案1】:

您可以通过查看 this 链接快速了解 matplotlib 中的后端所指的内容。

感谢@ImportanceOfBeingErnest 为我提供了必要的资源。

import matplotlib

#Use the line below to set a backend for matplotib
matplotlib.use('TkAgg')

from PIL import Image
from pylab import *

im = array(Image.open('empire.jpg'))
imshow(im)

print ('Please click 3 points')
x = ginput(3)

print ('you clicked:',x)
show()

如果“TkAgg”不适合您,您可以按给定顺序尝试这些其他 GUI 后端。

  • WX
  • QTAgg
  • QT4Agg

【讨论】:

    猜你喜欢
    • 2016-09-18
    • 2022-12-01
    • 2020-06-28
    • 2019-08-21
    • 2017-05-15
    • 2020-01-08
    • 2021-01-26
    • 2020-02-06
    • 1970-01-01
    相关资源
    最近更新 更多