Using ginput in my code returns the error: matplotlib is currently using a non-GUI backend

1.3k Views Asked by At

I'm trying to figure out how ginput(3) works in this code, but when I run it, it returning a UserWarning saying: "matplotlib is currently using a non-GUI backend, "

Please help me out on this.

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()

UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure "matplotlib is currently using a non-GUI backend, "

1

There are 1 best solutions below

0
Sumanth Reddy On BEST ANSWER

You can take a quick look at what a backend in matplotlib refers to, by checking out this link.

Thanks @ImportanceOfBeingErnest for providing me with the necessary resource.

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()

You could try out these other GUI backends in the given order, if "TkAgg" doesn't work out for you.

  • WX
  • QTAgg
  • QT4Agg