Plot Objects

Plot objects maps a set of abscissa values to a set of ordinate values and creates a polyline connecting the points. Note that plot objects do not automatically create axes for the plot lines they create.

Creating Plot Objects

Create a plot line by providing a vector of Y values, and, optionally, a vector of X values. If no X values are provided, the Y values are plotted against the element indices of the Y vector.

The following statement creates a plot object plotting the values [2, 9, 4, 4, 6, 2, 8] against their own indices:

myplot = OBJ_NEW('IDLgrPlot', [2,9,4,4,6,2,8]) 

The following statements plot the same data versus a series of primes:

datay = [2,9,4,4,6,2,8] 
datax = [0,1,2,5,7,11,13] 
myplot = OBJ_NEW('IDLgrPlot', datax, datay) 

See "IDLgrPlot" (IDL Reference Guide) for details on creating plot objects.

Using Plot Objects

Plot objects can be configured to draw regular X vs. Y, histogram, or polar plots. Set the HISTOGRAM property to create a histogram plot, or the POLAR property to create a polar plot. The following example uses the same data set to create a standard plot, a histogram plot, and a standard plot using a boxcar filter. All three plots are displayed in the same view.

mywindow = OBJ_NEW('IDLgrWindow') 
myview = OBJ_NEW('IDLgrView', VIEWPLANE_RECT=[-10,-10,20,20]) 
mymodel = OBJ_NEW('IDLgrModel') 
 
x = (FINDGEN(21) / 10.0 - 1.0) * 10.0 
y = [3.0, -2.0, 0.5, 4.5, 3.0, 9.5, 9.0, 4.0, 1.0, -8.0, $ 
    -6.5, -7.0, -2.0, 5.0, -1.0, -2.0, -6.0, 3.0, 5.5, 2.5, -3.0] 
myplot1 = OBJ_NEW('IDLgrPlot', x, y, COLOR=[120, 120, 120]) 
myplot2 = OBJ_NEW('IDLgrPlot', x, y, /HISTOGRAM, LINESTYLE=4) 
y2 = SMOOTH(y, 5) 
myplot3 = OBJ_NEW('IDLgrPlot', x, y2, LINESTYLE=2) 
 
myview->Add, mymodel 
mymodel->Add, myplot1 
mymodel->Add, myplot2 
mymodel->Add, myplot3 
mywindow->Draw, myview  

Figure 5-3: Plot Object

objplot6.gif

Minimum and Maximum Values

You can control the minimum and maximum values of data plotted by a plot object. Set the MAX_VALUE property of the plot object to disregard data values higher than a specified value. Set the MIN_VALUE property to disregard data values lower than a specified value. Floating-point Not-a-Number (NaN) values are also treated as missing data and are not plotted.

For example, the following statement changes the minimum and maximum values of the histogram plot, and re-draws the view object:

myplot2->SetProperty, MAX_VALUE=8, MIN_VALUE=2 
mywindow->Draw, myview 

Using Plotting Symbols

Set the SYMBOL property of a plot object equal to the object reference of a symbol object to display that symbol at each data point. For example, to use a triangle symbol at each data point, create the following symbol object, set the plot object's SYMBOL property, and re-draw:

mySymbol = OBJ_NEW('IDLgrSymbol', 5, SIZE=[.3,.3]) 
myplot1->SetProperty, SYMBOL=mySymbol 
mywindow->Draw, myview  
 

Figure 5-4: Plotting Symbols

objplot7.gif

Averaging Points

Use the NSUM property of the plot object to average the values of a group of data points before plotting. If there are m data points, m/NSUM data points are plotted. For example, the following statement causes IDL to average pairs of data points when plotting the line for the histogram plot.

myplot2->SetProperty, NSUM=2 
mywindow->Draw, myview 

Polar Plots

To create a polar plot, provide a vector of radius values, a vector of theta values, and set the POLAR property to a nonzero value. The following example creates a simple polar plot:

mywindow = OBJ_NEW('IDLgrWindow') 
myview = OBJ_NEW('IDLgrView', VIEWPLANE_RECT=[-100,-100,200,200]) 
mymodel = OBJ_NEW('IDLgrModel') 
r = FINDGEN(100) 
theta = r/5 
mypolarplot = OBJ_NEW('IDLgrPlot', r, theta, /POLAR) 
myview->Add, mymodel 
mymodel->Add, mypolarplot 
mywindow->Draw, myview  
 

Figure 5-5: Polar Plot

objplot8.gif