ppgplot examples

[efault : npat : hacks : ppgplot : examples]


exmaples / ex_arro.py
from Numeric import *
from ppgplot import *

# initialize ploting.
pgbeg("?",1,1)        # open ploting device
pgask(1)              # wait for user to press a key
pgswin(-10,10,-10,10) # set axis ranges
                      # label the plot
pgiden()              # put user-name and date on plot

# calculate a suitable function
f = arange(0,2*pi,0.25)
fx = cos(f);
fy = sin(f);

for i in range(f.shape[0]):
    pgslw(i%10+1)       # set line-width
    pgsls(i%5+1)        # set line-style
    pgsci(i%15+1)       # set color-index
    pgarro(fx[i],fy[i],10*fx[i],10*fy[i])

#close the plot.
pgend()


exmaples / ex_graph.py
import ppgplot, Numeric
import sys

# create an array 
xs=Numeric.array([1.,2.,3.,4.,5.])
ys=Numeric.array([1.,4.,9.,16.,25.])

# creat another array
yr = 0.1*Numeric.array(range(0,60))
xr = yr*yr

# pgplotting
ppgplot.pgopen('?')
ppgplot.pgenv(0.,10.,0.,20.,0,1)
ppgplot.pglab('(x)', '(y)', 'PGPLOT Example 1:  y = x\u2')
ppgplot.pgpt(xs,ys,9)
ppgplot.pgline(xr,yr)
ppgplot.pgclos()


exmaples / ex_sierp.py
from Numeric import *
from ppgplot import *

s602, c602 = sin(pi/3) / 2, cos(pi/3) / 2

def drawtriangle (p1, p2, p3, i):
    if (i > 5) :
	return
    l = sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
    pgmove(p1[0], p1[1])
    pgdraw(p2[0], p2[1])
    pgdraw(p3[0], p3[1])
    pgdraw(p1[0], p1[1])

    pgsci(1)
    drawtriangle(p1, [p1[0] + l/2, p1[1]], \
		 [p1[0] + l*c602, p1[1] + l*s602], i+1)
    pgsci(2)
    drawtriangle([p2[0] - l/2, p2[1]], p2, \
		 [p2[0] - l*c602, p2[1] + l*s602], i+1)
    pgsci(3)
    drawtriangle([p3[0] - l*c602, p3[1] - l*s602], \
		 [p3[0] + l*c602, p3[1] - l*s602], p3, i+1)

l = 1
p1, p2, p3 = [0,0], [l,0], [cos(pi/3), sin(pi/3)]

pgbeg('?')
pgask(1)
pgenv(0,1,0,1)
pgslw(5)
pgsci(1)
drawtriangle(p1,p2,p3,0)
pgend()


exmaples / ex_panel.py
from Numeric import *
from ppgplot import *

def fixenv (xrange=[0,1], yrange=[0,1], fname="none", ci = 2):
                             # set axis ranges.
    pgswin(xrange[0],xrange[1],yrange[0],yrange[1])     
    pgsci(ci)                # set color index.
    pgbox()                  # draw axes. 
    pgsci(1)                 # back to color index 1 (white)
    pglab("x","y",fname)     # label the plot

    
# initialize ploting.
pgbeg("?",2,2)  # open ploting device (2x2 pannels)
pgiden()        # put user-name and date on plot.
pgask(1)        # wait for user to press a key.

# calculate some suitable functions.
x = arange(0.01,6*pi,0.1)
y = zeros([2,2,x.shape[0]],Float64)
label = zeros([2,2],PyObject)
y[0,0] = sin(2*x)/x
label[0,0] = "sin(2*x)/x"
y[1,0] = sin(2*x)
label[1,0] = "sin(2*x)"
y[0,1] = x*sin(2*x)
label[0,1] = "x*sin(2*x)"
y[1,1] = sin(x) + sin(2*x) + sin(3*x)
label[1,1] = "sin(x) + sin(2*x) + sin(3*x)"

# do the plotting
for i in range(2):
    for j in range(2):
	pgpanl(i+1,j+1)
	fixenv([0.0,6*pi],[min(y[i,j]),max(y[i,j])],label[i,j], i*2+j+2)
	pgslw(6);          # set line-width to 6/201.
	pgsls(i*2+j+1)     # set the line style.
	pgline(x,y[i,j])   # plot the line.
	pgsls(1);          # recall line-style
	pgslw(1);          # recall line-width
#close the plot.
pgend()


exmaples / ex_cont.py
from Numeric import *
from ppgplot import *

# initialize ploting.
pgbeg("?",1,1)   # open ploting device
pgask(1)         # wait for user to press a key.
pgenv(1,40,1,40) # set axis ranges, and draw axes.
                 # label the plot.
pglab("x","y","z = cos(.3*sqrt(2*x) - .4*y/3)*cos(.4*x/3) + (x-y)/40.0")
pgiden()         # put user-name and date on plot.

# calculate a suitable function.
surf = zeros([40,40],Float32)
for i in range(1,41):
    for j in range(1,41):
	surf[i-1,j-1] = cos(.3*sqrt(2*i) - .4*j/3)*cos(.4*i/3) + (i-j)/40.0
mns, mxs = min(ravel(surf)), max(ravel(surf))


# do the ploting.
pggray_s(surf)        # image map of the array surf.
pgsci(2)              # change color index to 2 (red).
pgcont_s(surf,10)     # trace 10 contours on array surf.
pgsci(3)              # set color index to 3 (green).
for i in range(10):   # label the contours.
    c = mns + i*((mxs - mns) / (10-1))
    pgconl_s(surf,c,str(i))
pgsci(1)              # set colndx back to 1 (white)
	              # plot a wedge to the right of the image.
pgwedg_s(max(ravel(surf)),min(ravel(surf)), "RG")
#close the plot.
pgend()


Updated: Mon Oct 13 01:55:46 EEST 2003