Skip to content

Commit 422c13e

Browse files
cgohlkemdboom
authored andcommitted
Miscellaneous fixes to get examples running under Python 3.x
1 parent 2f2ae95 commit 422c13e

18 files changed

+45
-29
lines changed

examples/animation/simple_3danim.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def Gen_RandLine(length, dims=2) :
1515
"""
1616
lineData = np.empty((dims, length))
1717
lineData[:, 0] = np.random.rand(1, dims)
18-
for index in xrange(1, length) :
18+
for index in range(1, length) :
1919
# scaling the random numbers by 0.1 so
2020
# movement is small compared to position.
2121
# subtraction by 0.5 is to change the range to [-0.5, 0.5]
@@ -37,7 +37,7 @@ def update_lines(num, dataLines, lines) :
3737
ax = p3.Axes3D(fig)
3838

3939
# Fifty lines of random 3-D lines
40-
data = [Gen_RandLine(25, 3) for index in xrange(50)]
40+
data = [Gen_RandLine(25, 3) for index in range(50)]
4141

4242
# Creating fifty line objects.
4343
# NOTE: Can't pass empty arrays into 3d version of plot()

examples/api/collections_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
theta = N.array(range(nverts)) * (2*N.pi)/(nverts-1)
3131
xx = r * N.sin(theta)
3232
yy = r * N.cos(theta)
33-
spiral = zip(xx,yy)
33+
spiral = list(zip(xx,yy))
3434

3535
# Make some offsets
3636
rs = N.random.RandomState([12345678])
3737
xo = rs.randn(npts)
3838
yo = rs.randn(npts)
39-
xyo = zip(xo, yo)
39+
xyo = list(zip(xo, yo))
4040

4141
# Make a list of colors cycling through the rgbcmyk series.
4242
colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c','y','m','k')]
@@ -114,7 +114,7 @@
114114
segs = []
115115
for i in range(ncurves):
116116
xxx = xx + 0.02*rs.randn(nverts)
117-
curve = zip(xxx, yy*100)
117+
curve = list(zip(xxx, yy*100))
118118
segs.append(curve)
119119

120120
col = collections.LineCollection(segs, offsets=offs)

examples/api/scatter_piecharts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
# some points on a circle cos,sin
2121
x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 10)).tolist()
2222
y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 10)).tolist()
23-
xy1 = zip(x,y)
23+
xy1 = list(zip(x,y))
2424

2525
# ...
2626
x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
2727
y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
28-
xy2 = zip(x,y)
28+
xy2 = list(zip(x,y))
2929

3030
x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
3131
y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
32-
xy3 = zip(x,y)
32+
xy3 = list(zip(x,y))
3333

3434

3535
fig = plt.figure()

examples/mplot3d/polys3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
for z in zs:
1616
ys = np.random.rand(len(xs))
1717
ys[0], ys[-1] = 0, 0
18-
verts.append(zip(xs, ys))
18+
verts.append(list(zip(xs, ys)))
1919

2020
poly = PolyCollection(verts, facecolors = [cc('r'), cc('g'), cc('b'),
2121
cc('y')])

examples/pylab_examples/arrow_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
199199
elif where == 'center':
200200
orig_position = array([[length/2.0, 3*max_arrow_width]])
201201
else:
202-
raise ValueError, "Got unknown position parameter %s" % where
202+
raise ValueError("Got unknown position parameter %s" % where)
203203

204204

205205

examples/pylab_examples/dashpointlabel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
(x,y) = zip(*DATA)
2323
ax.plot(x, y, marker='o')
24-
for i in xrange(len(DATA)):
24+
for i in range(len(DATA)):
2525
(x,y) = DATA[i]
2626
(dd, dl, r, dr, dp) = dash_style[i]
2727
#print 'dashlen call', dl

examples/pylab_examples/ellipse_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
NUM = 250
55

66
ells = [Ellipse(xy=rand(2)*10, width=rand(), height=rand(), angle=rand()*360)
7-
for i in xrange(NUM)]
7+
for i in range(NUM)]
88

99
fig = figure()
1010
ax = fig.add_subplot(111, aspect='equal')

examples/pylab_examples/image_demo3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pylab import *
33
try:
44
from PIL import Image
5-
except ImportError, exc:
5+
except ImportError:
66
raise SystemExit("PIL must be installed to run this example")
77

88
import matplotlib.cbook as cbook

examples/pylab_examples/integral_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def func(x):
1717
# make the shaded region
1818
ix = arange(a, b, 0.01)
1919
iy = func(ix)
20-
verts = [(a,0)] + zip(ix,iy) + [(b,0)]
20+
verts = [(a,0)] + list(zip(ix,iy)) + [(b,0)]
2121
poly = Polygon(verts, facecolor='0.8', edgecolor='k')
2222
ax.add_patch(poly)
2323

examples/pylab_examples/line_collection2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# where onoffseq is an even length tuple of on and off ink in points.
2222
# If linestyle is omitted, 'solid' is used
2323
# See matplotlib.collections.LineCollection for more information
24-
line_segments = LineCollection([zip(x,y) for y in ys], # Make a sequence of x,y pairs
24+
line_segments = LineCollection([list(zip(x,y)) for y in ys], # Make a sequence of x,y pairs
2525
linewidths = (0.5,1,1.5,2),
2626
linestyles = 'solid')
2727
line_segments.set_array(x)

0 commit comments

Comments
 (0)