I have a script which plots some image:
from matplotlib import pyplot as plt
from matplotlib import image as mpimg
(...)
fig = plt.figure()
ax = fig.add_subplot(111)
(...)
for img in images:
imgdata = mpimg.imread(img)
ax.imshow(imgdata)
plt.show(block=True)
Unfortunately, it seems to be unpossible to block the GUI and wait for user input with fig.show(). Just plt.show() blocks...so I have to use the plt.show solution?
Additionally I am listening to user events like this:
cid = fig.canvas.mpl_connect('key_press_event', on_key_press)
def on_key_press(event):
if event.key == "n":
ax.cla()
plt.show(block=False)
My intention is to listen for 'n' (like 'next') and then continue with the for loop, hence loading the next image data and plotting it, waiting for the user input again and so on...
However, the second call show() (plt.show(block=False)) updates the image (so the data of ax is cleared) but the lock is not released - the for loop does not continue. How could I achieve this behavior?
EDIT: I need the event.xdata, event.ydata, event.x, event.y values of matplotlib, so implementing a "hack" with something like input() and therefore letting python wait for user input in the console (and using matplotlib with block=False every time) would not solve my problem.
ginputfor mouse coordinates but I need key listeners, too. I want to create key shortcuts for basic operations like increase/decrease brightness, save image, load next image, ...