[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does IDL calculate the graph axis values?



Declan Vogt wrote:

> I'd like to find out what IDL will use as the max and min values for a
> graph axis before it actually plots the axis. I've been doing this by
> creating a window, drawing the axis, and reading !x.crange, then erasing
> the window, but it's not very elegant, and it doesn't work for
> postscript.
>
> Does anyone know if there is an IDL routine I can call?

I don't think there's a built-in routine for this purpose. However you can
always use the Z buffer as a temporary graphics device:

Say your data is defined as follows:

x = findgen(200) * 0.1
y = sin(x)

First you save the current graphics setup:

entry_device = !d.name
entry_window = !d.window
entry_config = {x:!x, y:!y, z:!z, map:!map}

Then you create a temporary plot in the Z buffer:

set_plot, 'Z'
device, z_buffer=0
plot, x, y, /nodata, xstyle=4, ystyle=4, /noerase, /ynozero
xrange = !x.crange
yrange = !y.crange

Then you restore the entry graphics setup:

set_plot, entry_device
if (entry_window ge 0) then wset, entry_window
!x = entry_config.x
!y = entry_config.y
!z = entry_config.z
!map = entry_config.map

The x and y axis ranges computed by IDL are then returned:

print, xrange, yrange
      0.00000      20.0000
     -1.00000      1.00000

This method does not require a graphics window to be open, does not care
what graphics device is active, does not disturb the contents of the Z
buffer, and does not disturb the current plot settings.

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley