File: xw15.py

package info (click to toggle)
plplot 5.3.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 26,248 kB
  • ctags: 11,687
  • sloc: ansic: 86,045; xml: 17,249; sh: 12,400; tcl: 8,113; cpp: 6,824; perl: 4,383; python: 3,915; makefile: 2,899; java: 2,788; fortran: 290; sed: 5; awk: 1
file content (91 lines) | stat: -rw-r--r-- 2,348 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from Numeric import *
from plplot import *

XPTS = 35		# Data points in x
YPTS = 46		# Data points in y


def main():
# Does a variety of shade plots with discrete colours and patterns.

    # Do not fiddle with cmap1 since this example actually uses cmap0.
    # Furthermore, if you do fiddle with cmap1, it will screw up other
    # plots (unless you return to default cmap1 like is done with eighth
    # example.
    x = (arrayrange(XPTS) - (XPTS / 2)) / float(XPTS / 2)
    y = ((arrayrange(YPTS) - (YPTS / 2)) / float(YPTS / 2)) - 1.
    x.shape = (-1,1)
    z = x*x - y*y + (x - y)/(x*x+y*y + 0.1)
    x.shape = (-1,)
    zmin = min(z.flat)
    zmax = max(z.flat)
    
    plot1(z, zmin, zmax)
    plot2(z, zmin, zmax)
    
    # Restore defaults
    plcol0(1)
	
def plot1(z, zmin, zmax):
# Illustrates a single shaded region

    pladv(0)
    plvpor(0.1, 0.9, 0.1, 0.9)
    plwind(-1.0, 1.0, -1.0, 1.0)
    
    shade_min = zmin + (zmax-zmin)*0.4
    shade_max = zmin + (zmax-zmin)*0.6
    sh_cmap = 0
    sh_color = 7
    sh_width = 2
    min_color = 9
    min_width = 2
    max_color = 2
    max_width = 2
    
    plpsty(8)
    
    # Just use identity transform on indices of z mapped to -1, 1 range
    # in X and Y coordinates
    plshade( z, -1., 1., -1., 1.,
    shade_min, shade_max, sh_cmap, sh_color, sh_width,
    min_color, min_width, max_color, max_width, 1)
							
    plcol0(1)
    plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0)
    plcol0(2)
    pllab("distance", "altitude", "Bogon flux")

def plot2(z, zmin, zmax):
# Illustrates multiple adjacent shaded regions, using different fill
# patterns for each region.

    pladv(0)
    plvpor(0.1, 0.9, 0.1, 0.9)
    plwind(-1.0, 1.0, -1.0, 1.0)
    
    sh_cmap = 0
    sh_width = 2
    min_color = 0
    min_width = 0
    max_color = 0
    max_width = 0
    
    for i in range(10):
	shade_min = zmin + (zmax - zmin) * i / 10.0
	shade_max = zmin + (zmax - zmin) * (i +1) / 10.0
	sh_color = i+6
	plpsty((i + 2) % 8 + 1)
    
	# Just use identity transform on indices of z mapped to -1, 1 range
	# in X and Y coordinates
	plshade( z, -1., 1., -1., 1.,
	shade_min, shade_max, sh_cmap, sh_color, sh_width,
	min_color, min_width, max_color, max_width, 1)

    plcol0(1)
    plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0)
    plcol0(2)
    pllab("distance", "altitude", "Bogon flux")

main()