Each data point can be marked with a symbol and/or connected with lines. The value of the keyword parameter PSYM selects the marker symbol, as described in the IDL Reference Guide. For example, a value of 1 marks each data point with the plus sign (+), 2 is an asterisk (*), etc. Setting PSYM to minus the symbol number marks the points with a symbol and connects them with lines. A value of -1 marks points with a plus sign (+) and connects them with lines. Note also that setting PSYM to a value of 10 produces histogram style plots in which a horizontal line is drawn across each x bin.
Frequently, when data points are plotted against the results of a fit or model, symbols are used to mark the data points while the model is plotted using a line. The figure below illustrates this, fitting the Sockeye population values to a quadratic function of the year. The IDL function POLY_FIT is used to calculate the quadratic.
The statements used to construct the above plot are as follows:
; Define variables. @plot01 ; Use the LINFIT function to fit the data to a line: coeff = LINFIT(YEAR, SOCKEYE) ;YFIT is the fitted line: YFIT = coeff[0] + coeff[1]*YEAR ; Plot the original data points with PSYM = 4, for diamonds: PLOT, YEAR, SOCKEYE, /YNOZERO, PSYM = 4, $ TITLE = 'Quadratic Fit', XTITLE = 'Year', $ YTITLE = 'Sockeye Population' ; Overplot the smooth curve using a plain line: OPLOT, YEAR, YFIT
Alternatively, you can run the following batch file to create the plot:
@plot03
See Running the Example Code if IDL does not find the batch file.
The USERSYM procedure allows you to define your own symbols by supplying the coordinates of the lines used to draw the symbol. The symbol you define can be drawn using lines or it can be filled using the polygon filling operator. USERSYM accepts two vector parameters: a vector of x values and a vector of y values. The coordinate system you use to define the symbol's shape is centered on each data point, and each unit is approximately the size of a character. For example, to define the simplest symbol, use a one character-wide dash centered over the data point:
USERSYM, [-.5, .5], [0, 0]
The color and line thickness used to draw the symbols are also optional keyword parameters of USERSYM. The following code illustrates the use of USERSYM to define a new symbol-a filled circle:
; Make a vector of 16 points, A[i] = 2pi/16: A = FINDGEN(17) *(!PI*2/16.) ; Define the symbol to be a unit circle with 16 points, ; and set the filled flag: USERSYM, COS(A), SIN(A), /FILL
Using the variables defined in the above example, we then create the plot, specifying 8 (user-defined) for the PSYM keyword to PLOT:
PLOT, YEAR, SOCKEYE, /YNOZERO, PSYM = 8, $ TITLE = 'Quadratic Fit', XTITLE = 'Year', $ YTITLE = 'Sockeye Population' ; Overplot the smooth curve using a plain line: OPLOT, YEAR, YFIT
The following figure shows the result of this code:
See USERSYM for additional details.
Using the keyword PSYM=10 with the PLOT routines draws graphs in the histogram mode, connecting points with vertical and horizontal lines. This next figure illustrates the comparison between the distribution of the IDL normally distributed random number function (RANDOMN) to the theoretical normal distribution.
The plot was produced by the following IDL commands:
; Two-hundred values ranging from -5 to 4.95: X = FINDGEN(200) / 20. - 5. ; Theoretical normal distribution, scale so integral is one: Y = 1/SQRT(2.*!PI) * EXP(-X^2/2) * (10./200) ; Approximate normal distribution with RANDOMN, ; then form the histogram. H = HISTOGRAM(RANDOMN(SEED, 2000), $ BINSIZE = 0.4, MIN = -5., MAX = 5.)/2000. ; Plot the approximation using "histogram mode." PLOT,FINDGEN(26) * 0.4 - 4.8, H, PSYM = 10 ; Overplot the actual distribution: OPLOT, X, Y * 8.