1
# Copyright (c) 1996, 1997, The Regents of the University of California.
2
# All rights reserved. See Legal.htm for full text and disclaimer.
5
from scipy_base.fastumath import *
6
from GistPlotter import *
7
GraphicsError = "GraphicsError"
10
graphics = os.environ["PYGRAPH"]
14
if graphics [0:3] == "Nar" :
16
elif graphics == "Gist" :
19
raise GraphicsError , \
20
graphics + " is an unknown graphics package. Check PYGRAPH " + \
21
"environment variable."
23
def span (lb, ub, n) :
24
if n < 2: raise ValueError, "Third argument must be at least 2."
26
a = (ub - lb) / (n - 1.0)
27
return map(lambda x, A=a, B=b: A*x+B,range(n))
30
return reshape (array(n*span(lb,ub,n), Float), (n,n))
34
for i in range (len (args)) :
35
r = r + args[i] * args[i]
39
return reshape (array ((n - 1) * spanz (lb, ub, n), Float), (n-1, n-1))
41
def spanz (lb, ub, n) :
42
if n < 3 : raise ValueError, "3rd argument must be at least 3"
43
c = 0.5 * (ub - lb) / (n - 1.0)
45
a = (ub -c -b) / (n - 2.0)
46
return map (lambda x, A = a, B = b: A * x + B, range (n - 1))
49
self.t = 2*pi*arange (400, typecode = Float) / 399.0
57
self.phase = self.theta = 0.
58
self.dtheta = pi / (self.nsteps - 1)
59
self.dphase = 2 * pi / (self.nsteps - 1)
62
self.cost = cos (self.theta)
63
self.sint = sin (self.theta)
64
self.x = self.rc1 * self.cost + self.size * cos (self.na1 * self.t)
65
self.y = self.rc1 * self.sint + self.size * sin (self.nb1 * self.t +
69
self.x = self.rc2 * self.cost + self.size * cos (self.na2 * self.t)
70
self.y = self.rc2 * self.sint + self.size * sin (self.nb2 * self.t +
74
self.theta = self.theta + self.dtheta
75
self.phase = self.phase + self.dphase
77
from curve import Curve
80
i = raw_input ("Type in any string to continue; ^C to return to prompt. ")
83
print "\nComprehensive graphics test (sort of) for Python interface"
84
print "with Narcisse and (mainly) Gist. This mirrors Lee's low level"
85
print "routine. Each frame will be described at the terminal; compare"
86
print "what you see with the description, then hit <RETURN> to see"
87
print "the next test, or ^C (ctrl-C) to escape.\n"
88
print "Type 'demo()' to begin.\n"
90
from quadmesh import *
91
from cellarray import *
93
from animation2d import *
97
c1 = Curve ( y = [0,1] , marks = 1 , marker = "A")
98
pl = Plotter ( dpi = 75 )
99
g1 = Graph2d ( c1, plotter = pl , titles = "Curve marked with A" ,
100
title_colors = "blue")
102
print "\nA small (75 dpi) window with line marked A from (0,0) to (1,1)."
104
# pl = Plotter ( dpi = 100 )
105
# g1 = Graph2d ( c1, plotter = pl , titles = "Curve marked with A" ,
106
# title_colors = "fg")
108
# print "\nA large (100 dpi) window with line marked A from (0,0) to (1,1)."
110
c2 = Curve ( y = [1,0] , marks = 1 , marker = "B")
112
g1.change (titles = "New curve marked B.")
114
print "\nAdded line marked B from (0,1) to (1,0) in previous plot."
118
g1.change (axis_scales = "loglin", titles = "Same, x axis now logarithmic.")
120
print "\nSame, x axis now logarithmic."
122
g1.change (x_axis_scale = "lin", titles = "x axis back to linear.")
124
print "\nSame, x axis now linear again."
126
g1.change(axis_limits=[[1.2,1.8],[0.2,0.8]],
127
titles="Limits now 1.2<x<1.8, 0.2<y<0.8.")
129
print "\nLimits now 1.2<x<1.8, 0.2<y<0.8."
131
# g1.change(y_axis_limits=[0.4,0.6],
132
# titles="Limits now 1.2<x<1.8, 0.4<y<0.6")
134
# print "\nLimits now 1.2<x<1.8, 0.4<y<0.6"
136
g1.change(axis_limits="defaults",
137
titles="Limits now back to extreme values.")
139
print "\nLimits now back to extreme values."
141
x=10*pi*arange(200, typecode = Float)/199.0
142
c1 = Curve ( x = x , y = sin(x),marks = 1, marker= "A")
146
g1.change (titles = "Five cycles of a sine wave, marked A.")
148
print "\nFive cycles of a sine wave."
150
c1.set(marks = 0, width = 6 , type = "dash")
151
g1.change (titles = "A mark gone, bold dashed.")
153
print "\nTurn off A marker, plot curve as bold dashed."
155
x=2*pi*arange(200, typecode = Float)/199.0
157
for i in range (1,7) :
158
r = 0.5*i -(5-0.5*i)*cos(x)
160
crvs.append(Curve(y=r*sin(x),x=r*cos(x),marks=0, color=-4-i,label=s))
161
g1=Graph2d(crvs,plotter = pl,titles="Nested cardioids in colors")
163
print "\nNested cardioids in primary and secondary colors."
165
g1.change(titles = ["colors","cardioids","Nested","in many"],
166
title_colors = ["red","yellow","magenta","blue"])
168
print "\nThe same with four titles in many colors."
170
mks = ['.','+','*','o','x','A']
171
for i in range (1,7) :
172
crvs[i-1].set (color="fg", type = 0, marker = mks[i-1])
173
g1.change (titles = "Marked curves", title_colors = "fg")
175
print "\nChanges color to foreground, types to no lines."
176
print "Markers are point, plus, asterisk, circle, cross, and A."
178
for i in range (1,6) :
179
crvs[i-1].set (marks = 0, type = i-1)
180
crvs[i].set (type = 1, width = 4)
181
g1.change (titles = "Different curve types.")
182
print "\nChanges line types to solid, dash, dot, dashdot, dashdotdot."
183
print "Outermost cardioid becomes a thick solid curve."
186
ValueError = "ValueError"
193
q1 = QuadMesh ( x=array(xx, copy = 1), y=array(yy, copy = 1) )
194
g1.new(q1, plotter = pl, titles = "Round mesh with bites out of sides",
195
axis_limits = [[min(ravel(xx)),max(ravel(xx))],
196
[min(ravel(yy)),max(ravel(yy))]])
198
print "\nQuadrilateral mesh -- round with bites out of its sides."
200
q1.set (boundary = 1, vx = x+.5, vy=y-.5,ktype = "none", ltype = "none")
201
g1.change(titles = "Vector field on mesh.")
203
print "\nVelocity vectors. Try zooming and panning with mouse."
205
q1.set (vx = None, vy = None, z = mag (x+.5,y-.5),marks = 1,
206
boundary=1,boundary_type="dash",marker="A")
207
g1.change(titles = "Lettered contour plot, dashed boundary.")
209
print "\nLettered contours, with boundary dashed."
211
q1.set (filled=1, type = "dash", color = "white")
213
print "\nFilled lettered dashed contours, with boundary dashed."
215
q1.set(marks = 0,boundary_type="solid",levels=array([0.5,1.0,1.5]),
216
filled=1, contours = 1, type = "dash", color = "white",
218
g1.change(titles = "Filled mesh, dashed contours")
220
print "\nFilled mesh (color only) with three dashed contours overlaid."
222
print "\nAfter each new palette is installed, hit <RETURN> for the next."
223
pal=["heat.gp","stern.gp","rainbow.gp","gray.gp","yarg.gp","earth.gp"]
225
g1.quick_plot(color_card = pal[i],titles = "Palette " + pal[i])
228
pal = ["vg.gs", "boxed.gs", "vgbox.gs", "nobox.gs", "work.gs"]
229
q1.set (marks = 1,boundary_type="dash",levels = 8, filled = 0, color = "fg")
231
pl.set_style (pal [i])
232
## g1 = Graph2d (q1, plotter = pl, titles = "Style Name: " + pal[i])
233
g1.change (plotter = pl, titles = "Style Name: " + pal[i])
240
funky=cos(r)**2*cos(3*theta)
241
c1 = CellArray(z=funky)
243
g1.change (color_card = "earth.gp",
244
titles ="Cell array, three cycles in theta,r",
245
axis_limits = "defaults")
249
theta = a2 (0, 2*pi, 18)
253
ln = Lines (x0 = x, y0 = y, x1 = transpose (x), y1 = transpose (y))
254
g1 = Graph2d (ln, plotter = pl, xyequal = 1, titles = "Seventeen pointed star.")
256
print "\nAll 17 pointed stars."
259
print "\nNext we will see a lissajous-style animation."
260
print "First run without animation mode."
261
print "Second run with animation mode."
264
anim = Animation2d ( initialize = init, calculations = [calc1, calc2],
265
update = incr, animation = 0, nsteps = 200 )
267
g1 = Graph2d ( anim , plotter = pl)
270
anim.set (animation = 1)