Axis Objects
Axis objects provide a visual notation of data values in two- and three-dimensional plots and graphs. Each axis is represented by an individual axis object; that is, if you have a plot in X and Y, you will need to create an x-axis object and a y-axis object.
Note
Axis objects do not take their range values from data values or other objects, as you might expect if you are familiar with IDL Direct Graphics. Instead, axis objects have a default range of 0.0 to 1.0; you must explicitly set the range of values covered by the axis object using the RANGE property.
Creating Axis Objects
To create an axis object, specify an integer argument to the IDLgrAxis::Init method when calling OBJ_NEW. Specify 0 (zero) to create an x-axis object, 1 (one) to create a y-axis object, or 2 to create a z-axis object:
The various keywords to the Init method allow you to control the number of major and minor ticks, the tick length and direction, the data range, and other attributes. For example, to create an x-axis object whose data range is between –5 and 5, with the tick marks below the axis line, use the following command:
To suppress minor tick marks:
See "IDLgrAxis" (IDL Reference Guide) for details on creating axis objects.
Using Axis Objects
Suppose you wish to create an X-Y plot of some data and wish to include both x- and y-axes.
Example Code
The following example code is included in a procedure file named obj_axis.pro, located in the examples/doc/objects subdirectory of the IDL distribution. Run the example procedure by entering obj_axis at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT obj_axis.pro.
First, we create some data to plot, the plot object, and the axis objects:
data = FINDGEN(100) myplot = OBJ_NEW('IDLgrPlot', data) xaxis = OBJ_NEW('IDLgrAxis', 0) yaxis = OBJ_NEW('IDLgrAxis', 1)
Next, we retrieve the data range from the plot object and set the x- and y-axis objects' RANGE properly so that the axes will match the data when displayed:
By default, major tickmarks are 0.2 data units in length. Since the data range in this example is 0 to 99, we set the tick length to 2% of the data range instead:
xtl = 0.02 * (xr[1] - xr[0]) ytl = 0.02 * (yr[1] - yr[0]) xaxis->SetProperty, TICKLEN=xtl yaxis->SetProperty, TICKLEN=ytl
Create model and view objects to contain the object tree, and a window object to display it:
mymodel = OBJ_NEW('IDLgrModel')
myview = OBJ_NEW('IDLgrView')
mywindow = OBJ_NEW('IDLgrWindow')
mymodel->Add, myplot
mymodel->Add, xaxis
mymodel->Add, yaxis
myview->Add, mymodel
Use the SET_VIEW procedure to add an appropriate viewplane rectangle to the view object. (See Finding an Appropriate View Volume for information on SET_VIEW).
Now, display the plot:
Logarithmic Axes
Creating a plot of logarithmic data requires that you create a logarithmic axis as well. The example referenced here first creates a linear plot, then takes a logarithm of the same data and creates a log-linear plot.
Example Code
The example code for logarithmic axes is included in a procedure file named obj_logaxis.pro, located in the examples/doc/objects subdirectory of the IDL distribution. Run the example procedure by entering obj_logaxis at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT obj_logaxis.pro.
When you run this example, notice that you need to position your mouse cursor at the IDL command prompt and hit you Enter key to step through the program and arrive at the following output.

