Created
September 16, 2011 19:19
-
-
Save dwf/1222883 to your computer and use it in GitHub Desktop.
Using matplotlib + multiprocessing for asynchronous, interactive monitoring plots.
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
"""Demo of how to pop up plots asynchronously using separate processes.""" | |
from multiprocessing import Process | |
import time | |
import sys | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def demo(): | |
i = 0 | |
processes = [] | |
while True: | |
i += 1 | |
s = time.time() | |
while time.time() - s < 5: | |
print 'HA', | |
sys.stdout.flush() | |
def do_something(): | |
figno = i | |
f = plt.figure() | |
# Normally this will always be "Figure 1" since it's the first | |
# figure created by this process. So do something about it. | |
f.canvas.set_window_title('My stupid plot number %d' % i) | |
arr = np.random.uniform(size=(50, 50)) | |
plt.imshow(arr) | |
plt.show() | |
p = Process(None, do_something) | |
processes.append(p) # May want to do other things with objects | |
p.start() | |
if __name__ == "__main__": | |
demo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I encountered an error: