1
## Automatically adapted for scipy Oct 31, 2005 by
3
# Copyright (c) 1996, 1997, The Regents of the University of California.
4
# All rights reserved. See Legal.htm for full text and disclaimer.
7
from numpy.core.umath import *
8
from numpy.corelinalg import rand
13
i = raw_input ("Type in any string to continue; ^C to return to prompt. ")
16
GraphicsError = "GraphicsError"
19
graphics = os.environ["PYGRAPH"]
23
if graphics [0:3] == "Nar" :
25
elif graphics == "Gist" :
28
raise GraphicsError , \
29
graphics + " is an unknown graphics package. Check PYGRAPH " + \
30
"environment variable."
32
if graphics [0:3] == "Nar" :
33
print "This is a test of the Python interface to the Limeil Lab graphics"
34
print "package, Narcisse. You need Narcisse to be running. Fire it up by"
35
print "doing setenv PORT_SERVEUR 0, typing /dist/basis/Narcisse/bin/Narcisse &,"
36
print "and then do another senetv PORT_SERVEUR to the port number which"
37
print "appears in the Narcisse GUI."
39
print "This is a test of the Python interface to the Gist graphics package."
41
print "Invoke function demo () to run."
49
# The following computations define an interesting 3d surface.
51
arange (1, kmax + 1, typecode = Float), ones (lmax, Float))
53
ones (kmax, Float), arange (1, lmax + 1, typecode = Float))
54
zt = 5. + xr + .2 * rand (kmax, lmax) # ranf (xr)
55
rt = 100. + yr + .2 * rand (kmax, lmax) # ranf (yr)
57
z = z + .02 * z * rand (kmax, lmax) # ranf (z)
58
ut = rt / sqrt (rt ** 2 + zt ** 2)
59
vt = zt / sqrt (rt ** 2 + zt ** 2)
60
ireg = multiply.outer ( ones (kmax), ones (lmax))
61
ireg [0:1, 0:lmax] = 0
62
ireg [0:kmax, 0:1] = 0
64
ireg [1:15, 12:lmax] = 3
66
freg = ireg + .2 * (1. - rand (kmax, lmax)) # ranf (ireg))
67
freg = array (freg, Float)
68
#rt [4:6, 4:6] = -1.e8
69
z [3:10, 3:12] = z [3:10, 3:12] * .9
70
z [5, 5] = z [5, 5] * .9
71
z [17:22, 15:18] = z [17:22, 15:18] * 1.2
72
z [16, 16] = z [16, 16] * 1.1
75
x = arange (-20, 21, typecode = Float)
76
y = arange (-20, 21, typecode = Float)
77
z = zeros ( (41, 41), Float)
78
for i in range (0, 41):
79
for j in range (0, 41):
80
r = sqrt (x [i] ** 2 + y [j] ** 2) + 1e-6
81
z [i, j] = sin (r) / r
82
s1 = Surface (z = z, opt_3d = "s3", mask = "max")
83
g1 = Graph3d ( s1 , titles = "Sombrero function",
84
y_factor = 2.0) #, phi = 30., theta = 45.)
87
s1.set (opt_3d = "w3")
90
foo = zeros ( (kmax, lmax), Float)
91
for k in range (kmax) :
92
foo [k, 0:lmax] = log (arange (1, lmax + 1, typecode = Float))
94
for l in range (lmax) :
95
foo [k, l] = xxx * foo [k, l]
96
s1.new (x = xr, y = yr, z = foo, opt_3d = "w3")
97
g1.change ( titles = "Exponential surface, z logarithmic",
98
# phi = 30., theta = 45.,
99
axis_scales = ["lin", "lin", "log"],
100
z_contours_scale = "log", y_factor = 1.0)
105
zz = xr ** 2 + yr ** 2
106
g1.change ( titles = "Exponential surface, z linear", phi = 45.,
107
axis_scales = ["lin", "lin", "lin"] )
110
s1.new (z = zz, opt_3d = "w3")
111
g1.change ( z_contours_scale = "lin",
112
titles = "Graph of xr**2 + yr**2", phi = 35.)
115
zs = zeros ( (50, 25), Float)
116
xs = zeros ( (50, 25), Float)
117
ys = zeros ( (50, 25), Float)
118
ctheta = zeros (50, Float)
119
stheta = zeros (50, Float)
120
cphi = zeros (25, Float)
121
sphi = zeros (25, Float)
124
ctheta [i] = cos (2. * i / 49. * pi)
125
stheta [i] = sin (2. * i / 49. * pi)
127
cphi [i] = cos (pi * i / 24.)
128
sphi [i] = sin (pi * i / 24.)
130
zs [0:50, i:i + 1] = cphi [i]
132
xs [j, i] = sphi [i] * ctheta [j]
133
ys [j, i] = sphi [i] * stheta [j]
137
# Plot a sphere with a random distribution of colors
138
s1.new (mask = "sort", opt_3d = "s4", x = hx, y = hy, z = zs,
139
c = rand (50, 25)) # ranf (zs))
141
g1.change_plot (titles = "Randomly colored sphere", send = 1)
143
s1 = Surface (mask = "sort", opt_3d = "s4", x = hx, y = hy,
144
z = zs, c = rand (50, 25))
145
##m1 = Mesh3d (color_card = "random", opt_3d = "f4", mask = "min",
146
## x = array ( [0.5, 1.2, 1.4, 1.05], Float),
147
## y = array ( [1.2, 0.5, 1.4, 1.05], Float),
148
## z = array ( [0., 0., 0., 1.2], Float),
149
## c = array ( [0.4, 0.6, 0.6, 0.6], Float),
150
## avs = 1, tet = [ 1, array ([[3,0,1,2]],Int) ])
151
m1 = Slice (array ( [3, 3, 3, 3], Int),
153
[0.5, 1.2, 0.], [1.2, 0.5, 0.], [1.4, 1.4, 0.],
154
[0.5, 1.2, 0.], [1.4, 1.4, 0.], [1.05, 1.05, 1.2],
155
[0.5, 1.2, 0.], [1.05, 1.05, 1.2], [1.2, 0.5, 0.],
156
[1.2, 0.5, 0.], [1.05, 1.05, 1.2], [1.4, 1.4, 0.]
157
] ), array ( [0.4, 0.5, 0.6, 0.7], Float))
158
g1.new ([s1, m1], link = 1,
159
titles = "Randomly colored sphere and solid tetrahedron",
160
axis_limits = [[-0.62, 1.4],
161
[-0.62, 1.4], [-1.0, 1.5]],
162
send = 1, y_factor = 2.0) # phi = 55, theta = 30,
164
#pl.set_color_card (8) #random
165
#pl.set_3d_options ("f4") #flat 4d
166
#pl.set_grid_type ("none") #don't redraw axes
167
# Note to myself: When the mesh plotter is done, use it for the
168
# following. Python should never call a plotter directly.
169
#pl.plot_surface (array ( [0.5, 1.2, 1.4, 1.05], Float),
170
# array ( [1.2, 0.5, 1.4, 1.05], Float),
171
# array ( [0., 0., 0., 1.2], Float),
172
# array ( [0.4, 0.6, 0.6, 0.6], Float),
173
# array ( [3, 6, 9, 12, 1, 2, 3, 0, 2,
174
# 3, 0, 1, 3, 0, 1, 2], Int), 4)
177
s1 = Surface ( mask = "sort", opt_3d = "s4", x = xs, y = ys,
179
s2 = Surface ( mask = "sort", opt_3d = "wm", x = hx, y = hy, z = hz, c = zs)
182
# g1.change_plot ( link = 1 , titles = "Imploding Sphere in R3",
183
# phi = 70.0, theta = 30.0,
184
# axis_limits = [[-1., 1.], [-1., 1.], [-0.7, 3.0]])
185
g1.new ( [s1, s2], link = 1 , titles = "Two Spheres in R3",
186
axis_limits = [[-1., 1.], [-1., 1.], [-0.7, 3.0]],
188
## phi = 70.0, theta = 30.0,