Contour Maps
In a contour map of f(x,y), the world-coordinates are
x and y and the contours are lines of constant f.
The PGPLOT contouring routines (PGCONT
and
PGCONS
) require the input data to be stored in a
two-dimensional Fortran array F
, with element
F(I,J)
containing the value of the function $f(x,y)$ for
a point $(x_i, y_j)$. Furthermore, the function must be sampled on a
regular grid: the $(x,y)$ coordinates corresponding to
(I,J)
must be related to I
and
J
by:
$$\eqalign{x = a + bI
+ cJ
,\cr
y = d + eI
+ fJ
.\cr}
$$
The constants $a, b, c, d, e, f$ are supplied to PGCONT
in a six-element
Fortran array. The other input required is an array containing the
contour values, i.e., the constant values of $f$ corresponding to each
contour to be drawn. In the following example, we assume that values
have been assigned to the elements of array F
. We first find the
maximum and minimum values of F
, and choose 10 contour levels evenly
spaced between the maximum and minimum:
REAL F(50,50), ALEV(10), TR(6)
...
FMIN = F(1,1)
FMAX = F(1,1)
DO 300 I=1,50
DO 200 J=1,50
FMIN = MIN(F(I,J),FMIN)
FMAX = MAX(F(I,J),FMAX)
200 CONTINUE
300 CONTINUE
DO 400 I=1,10
ALEV(I) = FMIN + (I-1)*(FMAX-FMIN)/9.0
400 CONTINUE
Next, we choose a window and viewport, and set up an array TR
containing the 6 constants in the transformation between array indices
and world coordinates. In this case, the transformation is simple,
as we want $x = I
$, $y = J
$:
CALL PGENV(0.,50.,5.,45.,0,2)
TR(1) = 0.0
TR(2) = 1.0
TR(3) = 0.0
TR(4) = 0.0
TR(5) = 0.0
TR(6) = 1.0
Finally, we call PGCONT
; actually, we call it twice, to draw the first
five contours in color index 2 (red) and the remaining 5 in color index 3
(green):
CALL PGSCI(2)
CALL PGCONT(F,50,50,1,50,1,50,ALEV,5,TR)
CALL PGSCI(3)
CALL PGCONT(F,50,50,1,50,1,50,ALEV(6),5,TR)
Normally PGCONT
is preferable to PGCONS
. See the description in
Appendix A for suggestions as to when PGCONS
should be used.