~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/xplt/eztest.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 1996, 1997, The Regents of the University of California.
 
2
# All rights reserved.  See Legal.htm for full text and disclaimer.
 
3
 
 
4
from Numeric import *
 
5
from scipy_base.fastumath import *
 
6
from ezplot import *
 
7
 
 
8
def paws ( ) :
 
9
    i = raw_input ("Type in any string to continue; ^C to return to prompt. ")
 
10
    return
 
11
 
 
12
print "This program tests ezplot. Type demo () to begin the test."
 
13
paws ()
 
14
 
 
15
# ezcshow("false")
 
16
def demo ():
 
17
   import scipy
 
18
   rand = scipy.rand
 
19
   vsf = 0.
 
20
   c = 1
 
21
   s = 1000.
 
22
   kmax = 25
 
23
   lmax = 35
 
24
   # The following computations define an interesting 3d surface.
 
25
 
 
26
   xr = multiply.outer ( arange (1, kmax + 1), ones (lmax))
 
27
   yr = multiply.outer ( ones (kmax), arange (1, lmax + 1))
 
28
   zt = 5. + xr + .2 * rand (kmax, lmax)   # ranf (xr)
 
29
   rt = 100. + yr + .2 * rand (kmax, lmax)   # ranf (yr)
 
30
   z = s * (rt + zt)
 
31
   z = z + .02 * z * rand (kmax, lmax)   # ranf (z)
 
32
   ut = rt/sqrt (rt ** 2 + zt ** 2)
 
33
   vt = zt/sqrt (rt ** 2 + zt ** 2)
 
34
   ireg =  array(multiply.outer ( ones (kmax), ones (lmax)),'i')
 
35
   ireg [0:1, 0:lmax]=0
 
36
   ireg [0:kmax, 0:1]=0
 
37
   ireg [1:15, 7:12]=2
 
38
   ireg [1:15, 12:lmax]=3
 
39
   ireg [3:7, 3:7]=0
 
40
   freg=ireg + .2 * (1. - rand (kmax, lmax))  # ranf (ireg))
 
41
   freg=freg.astype (Float)
 
42
   #rt [4:6, 4:6] = -1.e8
 
43
   z [3:10, 3:12] = z [3:10, 3:12] * .9
 
44
   z [5, 5] = z [5, 5] * .9
 
45
   z [17:22, 15:18] = z [17:22, 15:18] * 1.2
 
46
   z [16, 16] = z [16, 16] * 1.1
 
47
   cgm("close")
 
48
   win("on")
 
49
   set_mesh(rt=rt,zt=zt,ireg=ireg)
 
50
   titleb("An interesting mesh")
 
51
   plotm()
 
52
   nf()
 
53
   paws()
 
54
   titleb("Plot with ranges")
 
55
   plotm(kstyle="dashed", lstyle = "dotted", krange = (0, 20), lrange = (0,10),
 
56
      color = "yellow", thick = 2)
 
57
   nf ( )
 
58
   paws()
 
59
   titleb("L lines only")
 
60
   plotb ( )
 
61
   plotm(kstyle="none", lstyle="dashed", color="orange")
 
62
   nf ( )
 
63
   paws ()
 
64
   k2 = 3
 
65
   l2 = 7
 
66
   plotb ( )
 
67
   titleb("Region 2 singled out")
 
68
   plotm (region = 2, kstyle = "dashed", lstyle = "dotted", color = "green")
 
69
   text("Region 2", zt [k2, l2], rt [k2, l2], 32.)
 
70
   nf ()
 
71
   paws ( )
 
72
   titlet("A different contour plot")
 
73
   plotc(pvar = z, lev = 20)
 
74
   nf ()
 
75
   paws ( )
 
76
   titlet("Same plot filled.")
 
77
   plotc(pvar = z, lev = 20, color = "fill")
 
78
   nf ()
 
79
   paws ( )
 
80
   clear_mesh ( )
 
81
   nz=20
 
82
   xs = array ( range (-nz-1, nz+1) )
 
83
   ys = xs
 
84
   zs = zeros ( (2*nz + 2, 2*nz + 2), Float)
 
85
   for i in range ( len (xs) ) :
 
86
      for j in range ( len (ys)) :
 
87
         rs = sqrt ( xs [i] * xs[i] + ys [j] * ys [j] ) + 1.e-12
 
88
         zs [i, j] = sin (rs) / rs
 
89
   titleb("Sombrero, contour plot")
 
90
   plotc (pvar = zs, zt = ys, rt = xs, lev = 12)
 
91
   nf ( )
 
92
   paws ( )
 
93
   titleb("Sombrero, logarithmic contour plot")
 
94
   plotc (pvar = zs, zt = ys, rt = xs, lev = -12)
 
95
   nf ( )
 
96
   paws ( )
 
97
   titleb("Sombrero, filled contour plot")
 
98
   plotc (pvar = zs, zt = ys, rt = xs, lev = 12, color = "fill")
 
99
   nf ( )
 
100
   paws ( )
 
101
   attr (labels = "yes")
 
102
   titleb("Sombrero, contour plot using plotz.")
 
103
   plotz (zs, xs, ys, lev = 12)
 
104
   nf ( )
 
105
   paws ( )
 
106
   attr (labels = "no")
 
107
   titleb("Sombrero, filled mesh, linear")
 
108
   plotf (zs, ys, xs)
 
109
   nf ( )
 
110
   paws ( )
 
111
   titleb("Sombrero, filled mesh, logarithmic")
 
112
   plotf (zs, ys, xs, cscale = "log")
 
113
   nf ( )
 
114
   paws ( )
 
115
   titleb("Sombrero, filled mesh, normal")
 
116
   plotf (zs, ys, xs, cscale = "normal")
 
117
   nf ( )
 
118
   paws ()
 
119
   nz = 80
 
120
   xs = array ( range (-nz-1, nz+1) )/4.
 
121
   ys = xs
 
122
   zs = zeros ( (2*nz + 2, 2*nz + 2), Float)
 
123
   for i in range ( len (xs) ) :
 
124
      for j in range ( len (ys)) :
 
125
         rs = sqrt ( xs [i] * xs[i] + ys [j] * ys [j] ) + 1.e-12
 
126
         zs [i, j] = sin (rs) / rs
 
127
   titleb("Sombrero, cell array plot")
 
128
   ploti (zs)
 
129
   nf ( )
 
130
   paws ( )
 
131
   # Vector stuff
 
132
   x = zeros ( (10, 10), Float)
 
133
   y = zeros ( (10, 10), Float)
 
134
   vx = zeros ( (10, 10), Float)
 
135
   vy = zeros ( (10, 10), Float)
 
136
   ireg = zeros ( (10, 10), Int)
 
137
   for i in range (10) :
 
138
      for j in range (10) :
 
139
         vy [i, j] = sin (i)
 
140
         vx [i, j] = cos (j)
 
141
         y [i, j] = j
 
142
         x [i, j] = i
 
143
   ireg [1:5, 1:5] = 1
 
144
   ireg [1:5, 5:10] = 2
 
145
   ireg [5:10, 1:5] = 3
 
146
   ireg [5:10, 5:10] = 4
 
147
   titleb ("A vector plot")
 
148
   plotv (y, x, vy, vx, ireg, vsc = 0.5, thick = 0.1, color = "red")
 
149
   nf ( )
 
150
   paws ( )
 
151
   set_mesh (rt = y, zt = x, ut = vy, vt = vx, ireg = ireg)
 
152
   titleb ("Vector plot, regions 1 and 4.")
 
153
   plotv (vsc = 0.35, region = [1,4], color = "blue")
 
154
   nf ( )
 
155
   paws ( )