keeping axis settings while adding data

hi guys,

is it somehow possible to force matplotlib (pylab) not to rescale the axes while adding some data to an existing plot? currently i have to do in a cycle (simplified example):
for (all data):
         p_U_ij.append(pylab.plot(r, data)
         pylab.xlim((0, 10))
         pylab.ylim((-5,10))

because after pylab.plot the plot axes are rescaled according to the data read in. i'd prefer setting it beforehand (with xlim, ylim) and then to do only pylab.plot in the cycle:

pylab.xlim((0, 10))
pylam.ylim((-5, 10))
for (all data):
         p_U_ij.append(pylab.plot(r, data)

is it somehow possible? even better would be to do the plotting in the background (not showing the window until the plotting is completely finished) - but i wasn't succesful in doing that. i'm using interactive mode because after creation of all plots using the code above, i'm updating the graphics during the calculation...

thanks for any hints!

best,
lubos

···

--
Lubos _@...2056..."
http://www.lubos.vrbka.net

Hi lubos,

you can avoid (auto-)rescaling in matplotlib:

···

-------------------------------------------------------------------------------------------------------
import pylab
ax = pylab.subplot(111, autoscale_on=False)
# or for an already existing axes instance 'ax' : ax.set_autoscale_on(False)
--------------------------------------------------------------------------------------------------------

If you want to plot in background you have to skip interactive mode (up to my
knowledge). If you nevertheless would like to change the results you can use
pylab.show() as last line in your script and change you data via
event-control - something like:
--------------------------------------------------------------------------------------
def function(event):
       if event.key == "c":
             pylab.cla()
       elif event.key == "u":
             # update the data
             pass
pylab.connect("key_press_event", function)
pylab.show()
----------------------------------------------------------------------------------------

best regards
Matthias

On Monday 07 July 2008 14:57:30 Lubos Vrbka wrote:

hi guys,

is it somehow possible to force matplotlib (pylab) not to rescale the
axes while adding some data to an existing plot? currently i have to do
in a cycle (simplified example):
for (all data):
         p_U_ij.append(pylab.plot(r, data)
         pylab.xlim((0, 10))
         pylab.ylim((-5,10))

because after pylab.plot the plot axes are rescaled according to the
data read in. i'd prefer setting it beforehand (with xlim, ylim) and
then to do only pylab.plot in the cycle:

pylab.xlim((0, 10))
pylam.ylim((-5, 10))
for (all data):
         p_U_ij.append(pylab.plot(r, data)

is it somehow possible? even better would be to do the plotting in the
background (not showing the window until the plotting is completely
finished) - but i wasn't succesful in doing that. i'm using interactive
mode because after creation of all plots using the code above, i'm
updating the graphics during the calculation...

thanks for any hints!

best,
lubos

hi,

you can avoid (auto-)rescaling in matplotlib:
-------------------------------------------------------------------------------------------------------
import pylab
ax = pylab.subplot(111, autoscale_on=False)
# or for an already existing axes instance 'ax' : ax.set_autoscale_on(False)
--------------------------------------------------------------------------------------------------------

this is exactly what i wanted, thanks!

If you want to plot in background you have to skip interactive mode (up to my knowledge). If you nevertheless would like to change the results you can use pylab.show() as last line in your script and change you data via event-control - something like:
--------------------------------------------------------------------------------------
def function(event):
       if event.key == "c":
             pylab.cla()
       elif event.key == "u":
             # update the data
             pass
pylab.connect("key_press_event", function)
pylab.show()
----------------------------------------------------------------------------------------

i don't know if i understand this correctly, but i think i cannot use this approach. i need to update the plot several times during the script (showing progress of an iterative procedure) - but pylab.show() causes the program to halt (until the window is closed).

why is it actually not possible to do something like the following piece of code?

ioff()
plot commands
draw()
ion()

best,
lubos

···

--
Lubos _@...2056..."
http://www.lubos.vrbka.net

hello,

why is it actually not possible to do something like the following piece of code?
ioff()
plot commands
draw()
ion()

actually, i did some test now (modification of the example http://www.scipy.org/Cookbook/Matplotlib/Animations site):

from pylab import *
ioff()
x = arange(0,2*pi,0.01) # x-array
line, = plot(x,sin(x))
draw()

displays nothing, then

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

displays nothing as well, but shows the same 'lag' as when running the whole code in interactive mode. that means that the data is processed, the graphics is plotted, just the window is not displayed.

i thought that ioff() is present exactly for this purpose. unfortunately, the documentation page

http://matplotlib.sourceforge.net/interactive.html

shows only an example where an image file is produced first with ioff(), the figure is closed and something is then displayed with ion().

when i later issue another plot() command (i.e., plot(random(20), random(20)), it is displayed and shows also the last part of the sin(x) plot...

the thing i want to achieve is maybe impossible - i'd just love to know why, or what am i doing wrong... i'm very grateful for any hints.

best,
lubos

···

--
Lubos _@...2056..."
http://www.lubos.vrbka.net

Lubos Vrbka wrote:

hello,

why is it actually not possible to do something like the following piece of code?
ioff()
plot commands
draw()
ion()

actually, i did some test now (modification of the example http://www.scipy.org/Cookbook/Matplotlib/Animations site):

from pylab import *
ioff()
x = arange(0,2*pi,0.01) # x-array
line, = plot(x,sin(x))
draw()

displays nothing, then

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

displays nothing as well, but shows the same 'lag' as when running the whole code in interactive mode. that means that the data is processed, the graphics is plotted, just the window is not displayed.

i thought that ioff() is present exactly for this purpose. unfortunately, the documentation page

http://matplotlib.sourceforge.net/interactive.html

shows only an example where an image file is produced first with ioff(), the figure is closed and something is then displayed with ion().

when i later issue another plot() command (i.e., plot(random(20), random(20)), it is displayed and shows also the last part of the sin(x) plot...

the thing i want to achieve is maybe impossible - i'd just love to know why, or what am i doing wrong... i'm very grateful for any hints.

Try looking at the dynamic_image_*.py in the examples directory (or examples/animation for version 0.98.x). I've personally used the dynamic_image_gtkagg.py approach for (what I think is) a similar use case to yours. Before finding that one, I went through a variety of approaches with threading, ion()/ioff() and draw().

Ryan

···

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma