Change Graphics Properties
You can easily change graphics properties either from the command line or inside of the graphics window after the graphics are initially created. This topic discusses the use of the command line to quickly try a different color, text size, or line thickness in your graphics.
Note: Some graphic properties can be changed interactively from the command line after creation. Others are available only when you are creating a graphic. Each graphic function lists all the available properties. The properties that can be set at creation are marked as "Init" for initialization. See the list of IDL Graphics Functions.
Note: At any time while you are working with a graphic, find out the current values of the properties by typing PRINT, <myPlotName>
at the IDL command line.
See the examples below to learn how to work with graphics properties.
PLOT Example
The following example shows two different plots displayed in one graphics window.
The code shown below creates the graphic shown above. You can copy the entire block and paste it into the IDL command line to generate it.
; Define some data for two plots.
sinewave = SIN(2.0*FINDGEN(200)*!PI/25.0) * EXP(-0.02*FINDGEN(200))
cosine = COS(2.0*FINDGEN(200)*!PI/25.0) * EXP(-0.02*FINDGEN(200))
myPlot1 = PLOT(sinewave, '-r')
myPlot2 = PLOT(cosine, '-b', /OVERPLOT, TITLE = 'Combined plots')
To see an explanation of the properties for these plots, see Multiple graphics in one window. The general syntax for changing graphics properties after creation is:
<graphic_var_name>.PROPERTYNAME = value
You can change the properties of either plot, using the variable name of each plot along with the "dot" syntax. The plot graphics here show several of the properties that you can change interactively. Try these commands at the command line to see the changes to the plots:
myPlot1.THICK = 2 ; change the line thickness
myPlot1.SYMBOL = 'D' ; changes the plot line symbol
myPlot1.SYM_FILLED = 1 ; fills the plot line symbol
myPlot1.SYM_FILL_COLOR = 'blue' ; changes the symbol color
myPlot2.color = 'goldenrod' ; changes the plot line color
myPlot2.thick = 3 ; changes the plot line thickness
These command-line changes result in this new graphic:
See the PLOT function for a list of the PLOT properties that you can change from the command line.
BARPLOT and ERRORPLOT Example
The BARPLOT and ERRORPLOT functions have many of the same properties as the PLOT function, but also contain some unique properties that you can change interactively. The following example shows some of them:
The code shown below creates the graphic shown above. You can copy the entire block and paste it into the IDL command line to generate it.
; Define the data
loc = INDGEN(6)
depth = [18.5, 17.2, 16.6, 19.2, 22.3, 17.1]
depth_error = [2.0, 1.0, 1.0, 2.0, 2.0, 1.0]
; Create the barplot
bplot = BARPLOT(depth, FILL_COLOR='green', $
YRANGE=[0,25], WIDTH=0.25)
; Create the error plot on top
eplot = ERRORPLOT(depth, depth_error, $
LINESTYLE=6, $
ERRORBAR_COLOR='orange', $
ERRORBAR_CAPSIZE=0.25, $
XTITLE='Location', YTITLE='Depth (cm)', $
TITLE='Permafrost depth (with error margins)', $
/OVERPLOT)
Change some of the errorplot's properties using the dot notation:
eplot.ERRORBAR_COLOR = 'red'
eplot.ERRORBAR_CAPSIZE = 1
eplot.THICK = 4
bplot.FILL_COLOR = 'goldenrod'
Change Graphics Properties with Dot Syntax
You can change the properties of either plot (shown above), using the variable name of each plot along with the "dot" syntax. The plot graphics here show several of the properties that you can change interactively. Try these commands at the command line to see the changes to the plots:
; FILL_COLOR changes the bar plot color
bplot.FILL_COLOR = 'light_blue'
; WIDTH changes the bar width
bplot.WIDTH = .50
; THICK defines the line thickness around the bars
bplot.THICK = 2
; BOTTOM_COLOR defines the
; bar shading color from the bottom
bplot.BOTTOM_COLOR = 'blue'
; ERRORBAR_CAPSIZE changes error cap size
eplot.ERRORBAR_CAPSIZE = .50
These changes result in a plot that looks very different: