Lesson 2: Contour Plotting

PV-WAVE provides many techniques, including contour plots, wire-mesh surfaces, and shaded surfaces, for visualizing 2D arrays. This lesson demonstrates the following:

Access the Data

Plot with CONTOURFS

Using Color in Contour Plots

Creating 3D Contour Plots

Filling the Contours with Color Using CONTOURFILL

Deleting Windows

Access the Data

First, you need a 2D data set to visualize. This example is a freely formatted file of the Pikes Peak, Colorado, region. The data set contains information about latitude, longitude, elevation, and snow depth, with 2400 single values per variable.

 

Note

If you are continuing from the previous lesson, you do not need to load this data and can skip this section.

To read the Pikes Peak data, do the following:

1.Read the data file, using status as the value returned by DC_READ_FREE. Enter:

status = DC_READ_FREE(!Data_Dir + 'wd_pike_elev.dat', $
lat, lon, elev, depth, /Column)

2. Use the INFO command to verify that the new variables lat, lon, elev, and depth were created. This command also tells you about the size and data type of the arrays:

INFO

Something similar to the following appears:

WAVE> INFO
% At $MAIN$  .
Code area used: 0.00% (0/768), Data area used: 1.00% (80/8000)
# local variables (including 0 parameters): 5/500
# common symbols: 0/0
LAT             FLOAT     = Array(2400)
LON             FLOAT     = Array(2400)
ELEV            FLOAT     = Array(2400)
DEPTH           FLOAT     = Array(2400)
STATUS          LONG      =            0
Saved Procedures:
SETDEMO     SETDEMO_MSNT     SETKEYS_MSNT       SETUP_KEYS
Saved Functions:
REVERSE         STRSPLIT

3. Create four 2D arrays to contain the data. Use the REFORM function to reformat the 1D arrays without changing the values numerically:

lat = REFORM(lat, 60, 40)
lon = REFORM(lon, 60, 40)
elev = REFORM(elev, 60, 40)
depth = REFORM(depth, 60, 40)

4. Enter the INFO command again to see how the arrays have been changed:

INFO

Plot with CONTOURFS

One way to view a 2D array is as a contour plot. The large number of keywords available make it possible to create almost any kind of contour plot.

1.Create a simple contour plot of the elevation by entering:

CONTOURFS, elev

The contour lines are displayed.

That command was very simple, but the resulting plot wasn’t as informative as it could be.

2. Create a customized CONTOURFS plot with more elevations and labels by entering:

CONTOURFS, elev, NLevels=8, /Follow

The NLevels keyword told CONTOURFS to plot eight equally-spaced elevation levels as shown in Contour Plot. The Follow keyword produced the labels on the contours.

3. Smooth the contours using the Spline keyword:

CONTOURFS, elev, NLevels=8, /Spline

The Spline keyword also produced labels on the contours, as shown in Contours with Labels.

4. Add more contour levels to get a better picture of the area, as shown in Contour Plot with more Contour Levels:

CONTOURFS, elev, NLevels=24

5. The same contour plot can be rendered from a 3D perspective as shown in Contour Plot Rendered as Surface Plot. First, set the default 3D viewing angle by entering:

SURFR

6. By using the T3D keyword in the next call to CONTOURFS, the contours will be drawn as seen from a 3D perspective. Enter:

CONTOURFS, elev, NLevels=24, /T3D

The 3D perspective of the contour is plotted as shown in 3D Perspective Contour Plot.

7. Display the latitude and longitude data along the x- and y-axes as shown in Contour Plot with Latitude and Longitude Displayed:

CONTOURFS, elev, lon, lat

8. Make the axes fit the data range by adding the X- and YStyle keywords as shown in Contour Plot with Fitted Axes:

CONTOURFS, elev, lon, lat, XStyle=1, YStyle=1

9. Add more contour levels:

CONTOURFS, elev, lon, lat, XStyle=1, YStyle=1, NLevels=10 

10. Double the thickness of the contour lines using the Thick keyword:

CONTOURFS, elev, lon, lat, XStyle=1, YStyle=1, NLevels=10, $
Thick=2.0

The thicker lines add more definition to the contours, as shown in Contour Plot with Thicker Lines.

11. Create a variable to specify the contour levels to display:

level = [5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000]

12. Display the specified contour levels as shown in Contour Plot with Custom Levels.

CONTOURFS, elev, lon, lat, XStyle=1, YStyle=1, Levels=level

13. Add labels that display the assigned values to the contour levels as shown in Contour Plot with Labels:

CONTOURFS, elev, lon, lat, XStyle=1, YStyle=1, $
Levels=level, C_Label=[1, 1, 1, 1, 1, 1, 1, 1]

14. Increase the size of the characters on the contour labels by 25%:

CONTOURFS, elev, lon, lat, XStyle=1, YStyle=1, $
Levels=level, C_Label=[1, 1, 1, 1, 1, 1, 1, 1], $
C_Charsize=1.25

The custom contour labels are larger than the tick labels, as shown in Contour Plot with Larger Custom Contour Labels.

 

Contour Plot

 

 

Contours with Labels

 

 

Contour Plot with more Contour Levels

 

 

Contour Plot Rendered as Surface Plot

 

 

3D Perspective Contour Plot

 

 

Contour Plot with Latitude and Longitude Displayed

 

 

Contour Plot with Fitted Axes

 

 

Contour Plot with Thicker Lines

 

 

Contour Plot with Custom Levels

 

 

Contour Plot with Labels

 

 

Contour Plot with Larger Custom Contour Labels

 

Using Color in Contour Plots

The TEK_COLOR command loads 32 predefined, unique, highly saturated colors into the bottom 32 indices of the colortable. When the TEK_COLOR colortable is in effect, you will be able to easily differentiate the different data sets in a plot.

1.Load a colortable that specifies the first 32 distinct colors in the lower end of the colortable:

TEK_COLOR

2. Bring up the COLOR_PALETTE window. This window displays the colors in the colortable, and enables you to see the 32 colors (0-31) in the TEK_COLOR palette. The COLOR_PALETTE window is useful as a reference when you are choosing plot colors.

COLOR_PALETTE

3. Create a variable that specifies the indices for the colors of the contour levels:

color1 = [11, 10, 1, 5, 8, 19, 7, 3, 31]

 

Note

The colortable indices specified in the array must be in the range {0...31} to take advantage of the bright colors created by the TEK_COLOR procedure. Colortable indices above 31 are not affected by the TEK_COLOR procedure, and will remain as defined by the previously loaded colortable.

4. Now display the contour levels in colors, smooth the contours, and add titles to the x- and y-axes:

CONTOURFS, elev, lon, lat, XStyle=1, YStyle=1, $
Levels=level, C_Label=[1, 1, 1, 1, 1, 1, 1, 1], $
C_Charsize=1.25, C_Colors=color1, /Spline, $
XTitle='Longitude', YTitle='Latitude', Thick=2

The color further defines the contour lines.

Creating 3D Contour Plots

You can create a 3D contour plot of the elevation using colors for the contour lines.

1.Use the color palette in TEK_COLOR to choose the colors, then create a variable to specify the color indices for the lines:

TEK_COLOR
color2 = [17, 23, 16, 2, 3, 5, 7, 1, 4, 31, 8, 9, 10, 11, 13, $
15, 30, 19, 20, 21]

2. Use the SURFR procedure to duplicate the rotation, translation and scaling of the SURFACE procedure:

SURFR

3. Create the contour plot in 3D space as shown in 3D Contour Plot:

CONTOURFS, elev, NLevels=20, C_Colors=color2, /Follow, /T3D

The lines are displayed in the specified colors.

4. Change the rotation and then re-draw the plot:

SURFR, AX=0, AZ=210
CONTOURFS, elev, NLevels=20, C_Colors=color2, /Follow, $
/T3D

The x-y plane appears parallel to the bottom of the window as shown in Rotated Contour Plot.

 

3D Contour Plot

 

 

Rotated Contour Plot

 

Filling the Contours with Color Using CONTOURFILL

You can shade enclosed contours generated by the CONTOURFS procedure with the CONTOURFILL procedure. Basic syntax for this procedure is:

CONTOURFILL, 'filename', z, x, y 

1.Use the CD command to move to a directory where you have write privileges:

CD, 'pathname'

2. Now plot the shaded areas, using the colors you specified earlier:

CONTOURFS, Path_filename='peak_elev.dat', elev, $
Col_Index=color1,/NoDrawPaths

3. Create a variable that specifies the color black:

color3 = 0

4. Now draw the contour with lines on top of the colors as shown in Filled Contours:

CONTOURFS, elev, XStyle=1, YStyle=1, Levels=level, $
C_Label=[1, 1, 1, 1, 1, 1, 1, 1], $
C_Charsize=1.25, C_Colors=color3, Col_Index=color1, $
Path_filename='peak_elev.dat'

The black lines clearly define the edges of the filled contours.

5. Make the lines show up better by doubling the thickness of each. Use the C_Thick keyword, which is specifically for the contour lines:

CONTOURFS, elev, XStyle=1, YStyle=1, Levels=level, $
C_Label=[1, 1, 1, 1, 1, 1, 1, 1],C_Charsize=1.25, $
C_Colors=color3, /NoErase, C_Thick=2, $
Col_Index=color1, Path_filename='peak_elev.dat'

The black contour lines appear twice as thick, as shown in Thicker Contour Lines.

 

Note

In addition to the CONTOURFS procedure, you can create contour plots with the CONTOUR2 procedure. CONTOUR2 is particularly useful for plotting irregularly gridded or “scattered” data. Furthermore, CONTOUR2 includes a Fill keyword that allows you to produce filled contours without using the CONTOURFS method. For detailed information and examples of CONTOUR2, see the PV-WAVE Reference.

For more information on contouring, see the PV‑WAVE User Guide.

 

Filled Contours

 

 

Thicker Contour Lines

 

Deleting Windows

Delete the open graphics windows by entering the following command:

WDELETE, /All

All the windows close.