Plotting with Direct Graphics

In IDL's Direct graphics system, plots are created with the PLOT procedure.

Creating plots using Direct graphics is not as convenient as using the iPlot tool, but may be desirable if you are incorporating images into a larger widget-based application, or if you need to programatically create a large number of processed images.

Creating a Simple 2-D Plot

In this example, we will plot a sine wave using the Direct graphics PLOT procedure.

  1. Since we are using Direct graphics, tell IDL to use a maximum of 256 colors and load a simple grayscale color map.
    2D_plot_6.gif
  2. DEVICE, RETAIN=2, DECOMPOSED=0
    LOADCT, 0

  3. Create the X-axis values. The FINDGEN function creates an array of one hundred elements, with each element equal to the value of the element's subscript.
  4. X= 2*!PI/100 * FINDGEN(100)

  5. Create the plot.
  6. PLOT, SIN(X)

Creating a 2-D Overplot

As with the IDL iPlot tool, you can overlay plots in Direct graphics. This is accomplished with the OPLOT procedure.

2D_plot_7.gif

It is often a good idea to change the color, line style, or line thickness parameters when calling OPLOT to distinguish the data sets. Refer to the OPLOT topic in the IDL Online Help for more information.

  1. If you have not already done so, do the example Creating a Simple 2-D Plot.
  2. Overplot a new sine wave with twice the frequency. Make the line twice as thick.
  3. OPLOT, SIN(2*X), THICK = 2

  4. Overplot yet another sine wave with triple the frequency. Instead of a line, use long dashes.
  5. OPLOT, SIN(3*X), LINESTYLE = 5

Printing a Direct Graphics Window

To print an image from an iTool window, you simply select Print from the iTool's Filemenu. Printing the contents of a Direct graphics window is more involved. To print a Direct graphics plot, enter the following commands at the IDL command line:

  1. Save the current plotting environment variable to a local variable.
  2. MYDEVICE=!D.NAME

  3. Designate the printer as the plot destination.
  4. SET_PLOT, 'printer'

  5. Plot your data, with the output now directed to the printer.
  6. PLOT, SIN(X)

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

  9. Restore the original output device for your plots.
  10. SET_PLOT, MYDEVICE

See The Printer Device for information on choosing a system printer for use when printing Direct graphics windows.

Note
If you experience problems printing on a UNIX platform, check that your printer is correctly configured. For more information, refer to the IDL Printer Setup for UNIX or Mac OS X topic in the IDL Online Help.