X
5269

Example of changing size, thickness, and font of Object Graphics axis titles and tickmark text


How can I change the size, thickness, and font of Object Graphics axis titles and tickmark text?

First create axis titles as text objects (IDLgrText objects). Use the SetProperty method to the axis object (IDLgrAxis object) to set the Title property equal to the text object. Use the GetProperty method to get the TickText property which is an instance of an IDLgrText object containing a vector of text strings.

To change the type style or size of the "title" or "tick text" text objects, create a font object (IDLgrFont object) and use the SetProperty method to the axis text object to specify the font and the type size.

The following code selects the times*bold eight point font for the axes title and tickmark text objects:
pro example_axis
data = findgen(100)
myplot = OBJ_NEW('IDLgrPlot', data)
xaxis = OBJ_NEW('IDLgrAxis', 0)
yaxis = OBJ_NEW('IDLgrAxis', 1)

; 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:
myplot -> GetProperty, XRANGE=xr, YRANGE=yr
xaxis -> SetProperty, RANGE=xr
yaxis -> SetProperty, RANGE=yr

; 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
xaxis_text = OBJ_NEW('IDLgrText','X Axis')
yaxis_text = OBJ_NEW('IDLgrText','Y Axis')
myfont = OBJ_NEW('IDLgrFont','times*bold',size=8)
xaxis_text->SetProperty, font=myfont
yaxis_text->SetProperty, font=myfont
xaxis->SetProperty, TITLE = xaxis_text
yaxis->SetProperty, TITLE = yaxis_text
;
xaxis->GetProperty, TICKTEXT = xtick_text
yaxis->GetProperty, TICKTEXT = ytick_text
xtick_text->SetProperty, font=myfont
ytick_text->SetProperty, font=myfont

; 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')
; use a viewgroup so that the heap will be cleaned up
; when the window is closed
mygroup= OBJ_NEW('IDLgrViewgroup')
mygroup->add, [myview, xaxis_text, yaxis_text, myfont]
mywindow = OBJ_NEW('IDLgrWindow', RETAIN=2, GRAPHICS_TREE=mygroup)
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.
SET_VIEW, myview, mywindow

; Now, display the plot:
mywindow -> Draw
end