I ran into this problem with show() again and again, and I'm sure I'm doing something wrong, but not sure of the right way to do what I want.
And [I think] what I want is some way to lock in the main thread until some event occurs in the GUI thread, something like this works for the first time:
from matplotlib import pyplot as p from scipy import rand im = (255*rand(480,640)).astype('uint8') fig = p.figure() ax = fig.add_subplot(111) ax.imshow(im)
p.show() blocks p.show() is called in the event handler. But when the same code is run a second time, it passes by p.show() and prints the original s, [-1, -1] .
I read conflicting information about whether p.show() should or should not be called more than once from the same program. It seems that it was intended to be used once and only once at the end of the script. Other use cases seem to somehow break into pyplot (state machine?).
I tried to use combinations of p.draw() and p.ion() and p.ioff() , but could not get the desired behavior (either things did not block properly, or the graphs did not appear at the right time).
I am also confused about how an event handler can see s in general here, and whether this is a bad way to pass input / output information. If I do not use the mutable container as an array or list, the information I want to set with the event handler is simply lost as a local variable. Is there any other method that I skip when the GUI thread can pass signals back to the main thread? Is there a way to block in the main, without periodic polling or waiting for a wait, for a signal from the event handler before continuing?
So, I think, ultimately, my main question is:
Is there a neat replacement for p.show() that does what I want (the same behavior as p.show() ), or does this type of code require a complete rethinking / rewriting?