I'm writing an application do display data that changes dynamically (the data being read from a socket).
As a dummy case, I try to draw a sine with an amplitude multiplied by 1.1 each second:
import numpy as np
import matplotlib.pyplot as plt
import time
x = np.arange(0, 10, 0.1);
y = np.sin(x)
for i in xrange(100):
plt.plot(x, y)
time.sleep(1)
y=y*1.1
This obviously not the way do it, but it shows my intentions.
How can it be done correctly?
EDIT: The following is the traceback output of the code suggested in @mskimm answer:
plt.show() #Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
File "<ipython-input-5-ed773f8e3e84>", line 7, in update
plt.draw()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 466, in draw
get_current_fig_manager().canvas.draw()
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 240, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/tkagg.py", line 12, in blit
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
RuntimeError: main thread is not in main loop
EDIT 2:
it turns out that same code works when run in qtconsole... (any idea why?)
How ever, each print rescaling to plot, so the "animation effect" is missing.
I try to use plt.autoscale_view(False,False,False) but that just caused no plot at all.