Created
October 27, 2017 09:32
-
-
Save smidm/745b4006a54cfe7343f4a50855547cc3 to your computer and use it in GitHub Desktop.
shows figure in matplotlib and waits for keypress or mouse click to continue, on figure close exits the loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pylab as plt | |
import numpy as np | |
fig = plt.figure() | |
closed = False | |
def handle_close(evt): | |
global closed | |
closed = True | |
def waitforbuttonpress(): | |
while plt.waitforbuttonpress(0.2) is None: | |
if closed: | |
return False | |
return True | |
fig.canvas.mpl_connect('close_event', handle_close) | |
while True: | |
plt.imshow(np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)) | |
plt.draw() | |
if not waitforbuttonpress(): | |
break | |
print('.') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment