Displaying Contours with Direct Graphics

Working with images using Direct graphics is not as convenient as using the iImage 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.

In this example, we will display a two-dimensional array as a contour plot using IDL Direct graphics. Enter the following commands at the IDL command line:

contour_3.gif

  1. If you have not already done so, restore the marbells.dat SAVE file.
  2. RESTORE, FILEPATH('marbells.dat', $
      SUBDIRECTORY=['examples', 'data'])

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

  5. Plot the contour.
  6. CONTOUR, elev

  7. Create a customized CONTOUR plot with more contour lines.
    contour_4.gif
  8. CONTOUR, elev, NLEVELS=8, $
      C_LABELS=[0,1]

    The NLEVELS keyword directs CONTOUR to plot eight equally-spaced contours. The C_LABELS keyword specifies which contour levels should be labeled (by default, every other contour is labeled).

     

     

  9. Similarly, you can create a filled contour plot where each contour level is filled with a different color (or shade of gray) by using the FILL keyword.
    contour_5.gif
  10. CONTOUR, elev, NLEVELS=8, /FILL

  11. To outline the resulting contours, make another call to CONTOUR and use the OVERPLOT keyword to overlay the previous plot.
  12. You can add tickmarks that indicate the slope of the contours (the tickmarks point downhill) by using the DOWNHILL keyword.
    contour_6.gif

    CONTOUR, elev, NLEVELS=8, $
      /OVERPLOT, /DOWNHILL

  13. CONTOUR can plot surface data in a three-dimensional perspective.
  14. First, set a three-dimensional viewing angle.

    SURFR

  15. By using the T3D keyword, the contours are drawn in a three-dimensional perspective.
    contour_7.gif
  16. CONTOUR, elev, NLEVELS=8, /T3D