4

The following code

plt.figure(1)
plt.subplot(211) 
plt.axis([0,100, 95, 4000])  
plt.plot(array1,array2,'r')
plt.ylabel("label")
plt.xlabel("label")
plt.subplot(212)
plt.specgram(array3)
plt.show() 

creates two nice diagrams. But how do you update its content without having to close the window?

I would need to create the window in one thread and, while a variable is being updated in the main code, the window is being updated using the variable.

How would you do it?

1 Answer 1

6

There are a few options: one is the great examples using mpl examples. the second is writing the loops your self so you can understand what is going on. Here is a simple example using the pylab.draw() function instead of show(), it is not fancy, but it will allow you to understand the basic stuff:

import pylab
import time

pylab.ion() # animation on

# Note the comma after line. This is placed here because 
# plot returns a list of lines that are drawn.
line, = pylab.plot(0,1,'ro',markersize=6) 
pylab.axis([0,1,0,1])

line.set_xdata([1,2,3])  # update the data
line.set_ydata([1,2,3])
pylab.draw() # draw the points again
time.sleep(6)

line1, = pylab.plot([4],[5],'g*',markersize=8) 
pylab.draw() 

for i in range(10):
    line.set_xdata([1,2,3])  # update the data
    line.set_ydata([1,2,3])
    pylab.draw() # draw the points again
    time.sleep(1)

print "done up there"
line2, = pylab.plot(3,2,'b^',markersize=6)     
pylab.draw() 

time.sleep(20)

I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.