Real time graphs

Hi, It looks good thanks, but I'm having a couple of

    > problems (being a python and matplotlib newbie).

You can use the "GUI neutral" pylab interface to do animation, but I
don't recommend it. This is mainly for teaching, demonstration and
testing purposes. For real work, I would settle on a GUI toolkit and
use their event loop (idle handling or timer) to do the animation. If
you are able to choose, I recommend GTKAgg as a backend for animation
because it is fastest (fltk is close, I haven't profiled qtagg; wxagg
and tkagg are significantly slower).

See, for example, examples/dynamic_image_gtkagg.py for an example of
how to use the gtk idle handler to do animation.

  > 2. It flashes between the specified axis and just fitting the
  > graph to the boundaries defined by the actual data. I want it
  > to stay using the specified axis all the time

I suspect this is because you are not properly controlling when
drawing is done. For example, if interactive mode is on and you do

for frame in myloop:
  axis(*rect)
  plot(blah)

your figure will be drawn twice. Once when axis is called and once
when plot is called. plot calls autoscale and may change the axis.
What you want is to turn interaction off and explicitly control the
time of the drawing with a call to canvas.draw() or pylab.draw()
When interaction is on, all pylab commands (including axis and draw in
this example) trigger a call to draw,
which is not you want. What you want is something like

# turn interaction off
for frame in myloop:
   plot(something) # or set your line data, whatever....
   axis(*rect)
   draw()

Here you only draw after the axis limits have been set.

Actually, in animation you rarely want to call plot for every frame.
It is much more efficient to save an object and set its data, as in
dynamic_image_gtkagg and anim.py. Calling plot in every frame creates
a new Line2D object on each iteration of the loop and is slow.

Hope this helps,
JDH

Hi,

That seems to have helped a fair bit, thanks for the tips.

Mark

···

On Fri, 2005-06-03 at 22:34 -0500, John Hunter wrote:

    > Hi, It looks good thanks, but I'm having a couple of
    > problems (being a python and matplotlib newbie).

You can use the "GUI neutral" pylab interface to do animation, but I
don't recommend it. This is mainly for teaching, demonstration and
testing purposes. For real work, I would settle on a GUI toolkit and
use their event loop (idle handling or timer) to do the animation. If
you are able to choose, I recommend GTKAgg as a backend for animation
because it is fastest (fltk is close, I haven't profiled qtagg; wxagg
and tkagg are significantly slower).

See, for example, examples/dynamic_image_gtkagg.py for an example of
how to use the gtk idle handler to do animation.

  > 2. It flashes between the specified axis and just fitting the
  > graph to the boundaries defined by the actual data. I want it
  > to stay using the specified axis all the time

I suspect this is because you are not properly controlling when
drawing is done. For example, if interactive mode is on and you do

for frame in myloop:
  axis(*rect)
  plot(blah)

your figure will be drawn twice. Once when axis is called and once
when plot is called. plot calls autoscale and may change the axis.
What you want is to turn interaction off and explicitly control the
time of the drawing with a call to canvas.draw() or pylab.draw()
When interaction is on, all pylab commands (including axis and draw in
this example) trigger a call to draw,
which is not you want. What you want is something like

# turn interaction off
for frame in myloop:
   plot(something) # or set your line data, whatever....
   axis(*rect)
   draw()

Here you only draw after the axis limits have been set.

Actually, in animation you rarely want to call plot for every frame.
It is much more efficient to save an object and set its data, as in
dynamic_image_gtkagg and anim.py. Calling plot in every frame creates
a new Line2D object on each iteration of the loop and is slow.

Hope this helps,
JDH