An obvious problem with the previous figure is that each line should be labeled showing what it depicts. The XYOUTS procedure is used to write graphic text at a given location. The call to XYOUTS to write a string starting at location (x, y) is as follows:
XYOUTS, X, Y, STRING
See XYOUTS for a complete list of keywords available when adding graphic text to a plot.
The next figure illustrates one method of annotating each graph with its name. The plot was produced exactly as was the previous figure, except that the x-axis range was extended to the year 1990 to allow room for the titles. To accomplish this, the keyword parameter
XRANGE = [1967, 1990] was added to the call to PLOT. A string vector, NAMES, containing the names of each sample population also is defined.
First, we define an array containing names for each of the lines plotted. (This array is also defined by the
plot01 batch file.)
The plot was produced with the following statements:
; Define variables: @plot01 ; Index of last point: N1 = N_ELEMENTS(YEAR) - 1 ; Plot first graph. Set the y-axis min and max ; from the min and max of all data sets. Default linestyle is 0. PLOT, YEAR, COHO, YRANGE = [MIN(ALLPTS), MAX(ALLPTS)], $ TITLE='Salmon Populations', XTITLE = 'Year', $ YTITLE = 'Fish (thousands)', XRANGE = [1965, 1990], $ /XSTYLE ; Loop for the three remaining scores, varying the linestyle: FOR I = 1, 3 DO OPLOT, YEAR, ALLPTS[*, I], LINE = I ; Append the title of each graph on the right: FOR I = 0, 3 DO XYOUTS, 1984, ALLPTS[N1, I], NAMES[I]
The previous figure also illustrates the use of a PostScript font (Times-Roman, in this case) for the titles and annotations. Note that PostScript fonts can only be used when the current graphics devices is set to PostScript.
This font was selected by first setting the default font, controlled by the system variable
plot02, located in the
examples/doc subdirectory of the IDL distribution. Note that running this batch files creates a PostScript file named
plot.ps in your current working directory. See Running the Example Code if IDL does not find the batch file.