Previous Getting Started with IDL: 2-D Plots Next

Simple Command Line Plotting

Simple plots can be charted using the PLOT procedure. Each call to PLOT establishes the plot window (the rectangular area enclosed by the axis), the plot region (the box enclosing the plot window and its annotation), the axis types (linear or logarithmic), and the scaling.

First, we'll plot a simple graph using a sine function. Use the FINDGEN function here to specify the dimensions of the array. The FINDGEN function returns a single-precision, floating-point array, with the specified dimension, where each element of the array is set to the value of its one-dimensional subscript.

  1. First, create a value for the X axis:
  2. X= 2*!PI/100 * FINDGEN(100)  
    

     

  3. Now, use PLOT to visualize the array:
  4. PLOT, SIN(X)  
    

     

    Figure 4-4: A simple sine wave using the PLOT command

    Figure 4-4: A simple sine wave using the PLOT command

Also, additional data can be added, as before, using the OPLOT procedure. Frequently, the color index, linestyle, or line thickness parameters are changed in each call to OPLOT to distinguish the data sets. The IDL Reference Guide contains a table describing the features you can change.

Using OPLOT

Now use OPLOT to plot the new information over the existing plot:

  1. Plot at twice the frequency:
  2. OPLOT, SIN(2*X)  
    

     

  3. Plot at three times the frequency:
  4. OPLOT, SIN(3*X)  
    

The results are shown in the following figure.

 

Figure 4-5: Graphing various data using the OPLOT command

Figure 4-5: Graphing various data using the OPLOT command

Printing a Plot

IDL allows you to easily print the plot just created. Simply enter the following command lines shown.

  1. First, save the original settings of your plotting environment:
  2. MYDEVICE=!D.NAME  
    

     

  3. Tell IDL that you wish to designate the printer to be the destination for the plot:
  4. SET_PLOT, 'printer'  
    

     

  5. Now plot again to the printer:
  6. PLOT, SIN(X)  
    

     

  7. Close the printing device:
  8. DEVICE, /CLOSE  
    

     

  9. Redesignate the original setting as the future destination for any plots:
  10. SET_PLOT, MYDEVICE  
      
    


Note
If you are having problems printing on UNIX, be sure your printer is configured correctly. For more information on this see IDL Printer Setup in UNIX or Mac OS X.

  IDL Online Help (March 06, 2007)