0

I have a python code in which I calculate a quantity for a large number of values of a parameter and then plot the quantity as a function of a parameter. Here is an example

t = np.linspace(1,100,10000)
q = np.zeros(10000)
for i in np.arange(10000)
   q[i] = func(t[i])
plt.plot(t,q)
plt.show()

However I want that the plot to get dynamically updated such that every time a new element of the q array is calculated it is added to the plot. How can I do that?

lovespeed
  • 4,835
  • 15
  • 41
  • 54
  • http://stackoverflow.com/questions/5179589/how-to-achieve-continuous-3d-plotting-i-e-update-a-figure-using-python-and-ma – Joran Beasley Oct 01 '12 at 20:24
  • http://stackoverflow.com/questions/15930529/python-matplotlib-dynamically-update-plot-array-length-not-known-a-priori – tacaswell Apr 10 '13 at 16:09

1 Answers1

2
from pylab import *

import time

ion()

tstart = time.time()               # for profiling
x = arange(0,2*pi,0.01)            # x-array
line, = plot(x,sin(x))

for i in arange(1,200):
    line.set_ydata(sin(x+i/10.0))  # update the data
    draw()                         # redraw the canvas


print 'FPS:' , 200/(time.time()-tstart)

ripped from the post i put in the comments ...

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • I do not really understand how to implement this in my case, because in this case it updates the full array in `line.set_ydata` line, where as in my case each time a new element of the array is updated. – lovespeed Oct 01 '12 at 20:51
  • @SthitadhiRoy check out [this answer](http://stackoverflow.com/questions/15930529/python-matplotlib-dynamically-update-plot-array-length-not-known-a-priori). It might help you. – Schorsch May 01 '13 at 13:19