Axis limits for dynamic plot.

Hi all,

I'm trying to do a plot which is dynamically updated.

However, the axis limits remain fixed even when the data goes out of the current ylim. Is there an easy way to keep the axis limits updated when the data gets updated?

I've trivially modified the anim.py example to show the problem. The sinusoid test data is updated with varying sinusoidal amplitude.

Using matplotlib 0.91.2

Thanks,
Venkat.

import pylab as p
import time
p.ion()

tstart = time.time() # for profiling
x = p.arange(0, 2*p.pi, 0.01) # x-array
i=0
nframes=100
A=2*p.sin(2*p.pi*(1/float(2*nframes))*i)
sindata=A*p.sin(x+i/10.0)
line, = p.plot(x, sindata)
ax=p.gca()
#ax.set_ylim(-2,2)
p.draw()
for i in p.arange(1,nframes):
    A=2*p.sin(2*p.pi*(1/float(2*nframes))*i)
    sindata=A*p.sin(x)
    line.set_ydata(sindata) # update the data
    p.draw() # redraw the canvas

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

The autoscaling infrastructure is not triggered when you manually set
the line data, only when you add a line to the Axes, eg when you call
"plot". You will need to either manually track this yourself and call
"ax.set_ylim:" to set the ylimits manually, or resuse the matplotlib
datalimits/autoscaling infrastructure. Unfortunatelym the API for the
latter has changed somewhat from 0.91 to 0.98, so I hesitate to tell
advise you to do this with 0.91 since it will break when you upgrade.

JDH

···

On Wed, Oct 8, 2008 at 12:23 PM, Venkat Ramanan <venkat@...1806...> wrote:

for i in p.arange(1,nframes):
   A=2*p.sin(2*p.pi*(1/float(2*nframes))*i)
   sindata=A*p.sin(x)
   line.set_ydata(sindata) # update the data
   p.draw() # redraw the canvas

John Hunter wrote:

Unfortunatelym the API for the
latter has changed somewhat from 0.91 to 0.98, so I hesitate to tell
advise you to do this with 0.91 since it will break when you upgrade.
  

Please let me know the instructions as if the version is 0.98. I'll upgrade to it soon.

Thanks,
Venkat.