PV-WAVE Foundation > Tutorial > 3D Plotting > Lesson 1: Surface Plotting
Lesson 1: Surface Plotting
This lesson demonstrates how to plot the surface of Pikes Peak, a mountain in Colorado. In this lesson, you’ll do the following:
Access the Data and Create Arrays
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. This file is located in <RW_DIR>\wave\data, where <RW_DIR> is your installation directory.
To access the 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
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
Create a Surface Plot
To create a surface plot, do the following:
1. To view the array elev as a 3D, wire-frame surface, enter the command:
SURFACE, elev
A wire-frame representation of the array is displayed.
The SURFACE command can be used to view your data from any angle.
2. Add the latitude and longitude information:
SURFACE, elev, lon, lat
The x- and y-axes of the new plot contain the latitude and longitude information.
3. Make the axes fit the data and increase the character size as shown in Figure 6-5: Surface Plot with Custom Axes:
SURFACE, elev, lon, lat, XStyle=1, CharSize=1.75
4. Make the peaks easier to see by drawing only the horizontal lines as shown in Figure 6-6: Surface Plot with Horizontal Lines Displayed. Specify that the bottom of the surface be drawn in yellow (color number 7):
; By default, the colortable is black and white, add 32 
; colors to the beginning of the colortable. The 7th color
; is yellow.
TEK_COLOR
SURFACE, elev, lon, lat, XStyle=1, CharSize=1.75, $
/Horizontal, Bottom=WoColorConvert(7)
The new plot demonstrates that plotting half as many lines as the wire frame mesh provides ample information.
 
note
The default viewing angle is quite suitable to get a general idea of the surface of this data, but if you need to rotate the plot to see the other side and most of the peaks use the AX and AZ keywords to control the SURFACE command. The keyword AX specifies the angle of rotation of the surface (in degrees towards the viewer) about the x-axis. The AZ keyword specifies the rotation of the surface in degrees counterclockwise around the z-axis.
5. Use the AX keyword to rotate the plot 60 degrees along the x-axis and use the AZ keyword to rotate it –30 degrees along the z-axis:
SURFACE, elev, lon, lat, XStyle=1, CharSize=1.75, $
/Horizontal, Bottom=WoColorConvert(7), AZ=-30, AX=60
The surface is displayed rotated about the x- and z-axes as shown in Figure 6-7: Rotated Surface Plot.
6. Now, draw only the yellow lines on the bottom of the surface as shown in Figure 6-8: Line-Only Plot of Surface:
SURFACE, elev, lon, lat, XStyle=1, CharSize=1.75, $
/Horizontal, Bottom=WoColorConvert(7), AZ=-30, $
AX=60, /Lower_Only
7. Draw the surface in the default viewing angle, adding a yellow skirt that begins at 5000 feet as shown in Figure 6-9: Surface Plot with Skirt:
SURFACE, elev, lon, lat, XStyle=1, CharSize=1.75, $
/Horizontal, Bottom=WoColorConvert(7), Skirt=5000
 
Figure 6-5: Surface Plot with Custom Axes
 
 
Figure 6-6: Surface Plot with Horizontal Lines Displayed
 
 
Figure 6-7: Rotated Surface Plot
 
 
Figure 6-8: Line-Only Plot of Surface
 
 
Figure 6-9: Surface Plot with Skirt
 
 
 
Display Data as a Shaded Surface
To view a 2D array as a light-source shaded surface, do the following:
1. First, enlarge the current window:
WINDOW, 0, XSize=800, YSize=800
2. Load one of the pre-defined PV-WAVE colortables by entering:
LOADCT, 5
3. To view the light-source shaded surface, simply enter the command:
SHADE_SURF, elev, lon, lat
A shaded surface of the array is displayed as shown in Figure 6-10: Shaded Surface Plot.
4. Outline the peaks in black using wire frame SURFACE command with the Horizontal keyword, as shown in Figure 6-11: Wire Outline Surface Plot.
SURFACE, elev, lon, lat, XStyle=4, YStyle=4, ZStyle=4, $
Color=WoColorConvert(0), /Horizontal, /NoErase
 
note
The NoErase keyword allows the SURFACE plot to be drawn over the existing SHADE_SURF plot. The XStyle, YStyle, and ZStyle keywords are used to select different styles of axes. Here, SURFACE is told not to draw the x-, y-, and z-axes because they were already drawn by the SHADE_SURF command.
You can plot the contour lines on the shaded surface, but you will need to save the 3D transformation matrix using the Save keyword.
5. Draw the shaded surface without axes and save the transformation:
SHADE_SURF, elev, lon, lat, XStyle=4, YStyle=4, ZStyle=4, $
/Save
6. Now draw the contour lines on the current plot:
; Create a variable to specify the contour levels to display:
level = [5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000]
CONTOUR, elev, lon, lat, XStyle=4, YStyle=4, ZStyle=4, $
/NoErase, Levels=level, /Follow, /T3D
The white contour lines follow the surface, as shown in Figure 6-12: Surface Plot with Contour Lines.
7. Now place colored contour lines above the shaded surface. When you loaded colortable 5, you overrode the TEK_COLOR palette, so you need to load it again:
TEK_COLOR 
8. Draw the contour lines in colors. Place them above the shaded surface by specifying displacement along the z-axis (ZValue) of 1.0:
SHADE_SURF, elev, lon, lat, XStyle=4, YStyle=4, $
ZStyle=4, /Save
CONTOUR, elev, lon, lat, XStyle=4, YStyle=4, ZStyle=4, $
/NoErase, Levels=level, C_Colors=WoColorConvert(2), $
/Follow, /T3D, ZValue=1.0
The colored contour lines are drawn at the top of the box as shown in Figure 6-13: Contour Lines Above Shaded Surface Plot.
 
Figure 6-10: Shaded Surface Plot
 
 
Figure 6-11: Wire Outline Surface Plot
 
 
Figure 6-12: Surface Plot with Contour Lines
 
 
 
Figure 6-13: Contour Lines Above Shaded Surface Plot
 
Use Color to Represent Data
You can specify a different array for the shading colors.
1. Use TEK_COLOR again to load 32 distinct colors at the beginning of the current colortable:
TEK_COLOR
2. Find the BYTSCL values of the depth and allow the first 32 distinct values to be excluded:
shade = BYTSCL(depth, Top=222) + 32b
3. Shade the elevation data plot with snow depth values:
SHADE_SURF, elev, lon, lat, XStyle=1, Shades=shade, $
Color=WoColorConvert(1)
 
note
The BYTSCL function scales and converts an array to BYTE data type. The Shades keyword specifies the same dimensions as the shade parameter, which contains the shading color indices.
The different shading colors correspond to snow depth, as shown in Figure 6-14: Elevation Data Plot.
The axes’ labels were drawn in white because this was specified by assigning the value of 1 (white in the TEK_COLOR palette) to the Color keyword.
4. Create a shaded surface that has the shading information provided by the elevation of each point:
shade = BYTSCL(elev, Top=222) + 32b
SHADE_SURF, elev, lon, lat, XStyle=1, Shades=shade, $
Color=WoColorConvert(1)
Now different shading colors on the plot correspond to different elevations, as shown in Figure 6-15: Shading Indicating Elevation.
5. Shade the snow depth data plot with elevation:
SHADE_SURF, depth, lon, lat, XStyle=1, Shades=shade, $
Color=WoColorConvert(1)
The shading colors correspond to the elevation data, as shown in Figure 6-16: Snow Depth Shading Indicating Elevation.
 
Figure 6-14: Elevation Data Plot
 
 
Figure 6-15: Shading Indicating Elevation
 
 
Figure 6-16: Snow Depth Shading Indicating Elevation
 
More Information on 3D Plotting
The SURFACE, CONTOUR, and SHADE_SURF commands have many more keywords that can be used to create even more complex, customized plots. For more information see the PV‑WAVE User’s Guide.