import numpy
import ppgplot
import math
 
# initialize ploting.
ppgplot.pgbeg("?",1,1)       # open ploting device
ppgplot.pgask(1)                 # wait for user to press a key before erasing.
ppgplot.pgenv(1,40,1,40)         # set axis ranges, and draw axes.
                         # label the plot.
ppgplot.pglab("x","y","z = cos(.3*sqrt(2*x) - .4*y/3)*cos(.4*x/3) + (x-y)/40.0")
ppgplot.pgiden()                 # put user-name and date on plot.
 
# calculate a suitable function.
surf = numpy.zeros([40,40],dtype=numpy.float32)
for i in range(1,41):
    for j in range(1,41):
        surf[i-1,j-1] = math.cos(.3*math.sqrt(2*i) - .4*j/3)*math.cos(.4*i/3) + (i-j)/40.0
mns, mxs = min(numpy.ravel(surf)), max(numpy.ravel(surf))
 
 
# do the ploting.
ppgplot.pggray_s(surf)           # image map of the array surf.
ppgplot.pgsci(2)                 # change color index to 2 (red).
ppgplot.pgcont_s(surf,10)        # trace 10 contours on array surf.
ppgplot.pgsci(3)                 # set color index to 3 (green).
for i in range(10):      # label the contours.
    c = mns + i*((mxs - mns) / (10-1))
    ppgplot.pgconl_s(surf,c,str(i))
ppgplot.pgsci(1)                 # set colndx back to 1 (white)
                         # plot a wedge to the right of the image.
ppgplot.pgwedg_s(max(numpy.ravel(surf)),min(numpy.ravel(surf)), "RG")
 
#close the plot.
ppgplot.pgend()
