Skip to content

Commit fc204fa

Browse files
authored
Merge pull request #7515 from efiring/kill_hold
Begin deprecation of "hold": remove from examples
2 parents 31ef622 + 973fe81 commit fc204fa

File tree

7 files changed

+20
-31
lines changed

7 files changed

+20
-31
lines changed

examples/pylab_examples/contour_image.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
3030
cmap = cm.PRGn
3131

32-
plt.figure()
32+
fig = plt.figure()
33+
fig.subplots_adjust(hspace=0.3)
3334

3435

3536
plt.subplot(2, 2, 1)
@@ -46,42 +47,38 @@
4647
# contour separately; don't try to change the edgecolor or edgewidth
4748
# of the polygons in the collections returned by contourf.
4849
# Use levels output from previous call to guarantee they are the same.
49-
cset2 = plt.contour(X, Y, Z, cset1.levels,
50-
colors='k',
51-
hold='on')
50+
51+
cset2 = plt.contour(X, Y, Z, cset1.levels, colors='k')
52+
5253
# We don't really need dashed contour lines to indicate negative
5354
# regions, so let's turn them off.
55+
5456
for c in cset2.collections:
5557
c.set_linestyle('solid')
5658

5759
# It is easier here to make a separate call to contour than
5860
# to set up an array of colors and linewidths.
5961
# We are making a thick green line as a zero contour.
6062
# Specify the zero level as a tuple with only 0 in it.
61-
cset3 = plt.contour(X, Y, Z, (0,),
62-
colors='g',
63-
linewidths=2,
64-
hold='on')
63+
64+
cset3 = plt.contour(X, Y, Z, (0,), colors='g', linewidths=2)
6565
plt.title('Filled contours')
6666
plt.colorbar(cset1)
67-
#hot()
6867

6968

7069
plt.subplot(2, 2, 2)
7170

7271
plt.imshow(Z, extent=extent, cmap=cmap, norm=norm)
7372
v = plt.axis()
74-
plt.contour(Z, levels, hold='on', colors='k',
75-
origin='upper', extent=extent)
73+
plt.contour(Z, levels, colors='k', origin='upper', extent=extent)
7674
plt.axis(v)
7775
plt.title("Image, origin 'upper'")
7876

7977
plt.subplot(2, 2, 3)
8078

8179
plt.imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
8280
v = plt.axis()
83-
plt.contour(Z, levels, hold='on', colors='k',
84-
origin='lower', extent=extent)
81+
plt.contour(Z, levels, colors='k', origin='lower', extent=extent)
8582
plt.axis(v)
8683
plt.title("Image, origin 'lower'")
8784

@@ -95,12 +92,11 @@
9592
# domain that is contoured does not extend beyond these pixel centers.
9693
im = plt.imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
9794
v = plt.axis()
98-
plt.contour(Z, levels, hold='on', colors='k',
99-
origin='image', extent=extent)
95+
plt.contour(Z, levels, colors='k', origin='image', extent=extent)
10096
plt.axis(v)
10197
ylim = plt.get(plt.gca(), 'ylim')
10298
plt.setp(plt.gca(), ylim=ylim[::-1])
103-
plt.title("Image, origin from rc, reversed y-axis")
99+
plt.title("Origin from rc, reversed y-axis")
104100
plt.colorbar(im)
105101

106102
plt.show()

examples/pylab_examples/contourf_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
interior = np.sqrt((X**2) + (Y**2)) < 0.5
2828
Z[interior] = np.ma.masked
2929

30-
3130
# We are using automatic selection of contour levels;
3231
# this is usually not such a good idea, because they don't
3332
# occur on nice boundaries, but we do it here for purposes
@@ -45,8 +44,7 @@
4544

4645
CS2 = plt.contour(CS, levels=CS.levels[::2],
4746
colors='r',
48-
origin=origin,
49-
hold='on')
47+
origin=origin)
5048

5149
plt.title('Nonsense (3 masked regions)')
5250
plt.xlabel('word length anomaly')
@@ -97,6 +95,8 @@
9795
# cmap.set_bad("red")
9896

9997
fig, axs = plt.subplots(2, 2)
98+
fig.subplots_adjust(hspace=0.3)
99+
100100
for ax, extend in zip(axs.ravel(), extends):
101101
cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend, origin=origin)
102102
fig.colorbar(cs, ax=ax, shrink=0.9)

examples/pylab_examples/layer_images.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def func3(x, y):
3232
Z1.shape = (8, 8) # chessboard
3333
im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
3434
extent=extent)
35-
plt.hold(True)
3635

3736
Z2 = func3(X, Y)
3837

examples/pylab_examples/scatter_masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
r = np.sqrt(x*x + y*y)
1111
area1 = np.ma.masked_where(r < r0, area)
1212
area2 = np.ma.masked_where(r >= r0, area)
13-
plt.scatter(x, y, s=area1, marker='^', c=c, hold='on')
13+
plt.scatter(x, y, s=area1, marker='^', c=c)
1414
plt.scatter(x, y, s=area2, marker='o', c=c)
1515
# Show the boundary between the regions:
1616
theta = np.arange(0, np.pi/2, 0.01)

examples/pylab_examples/toggle_images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" toggle between two images by pressing "t"
22
33
The basic idea is to load two images (they can be different shapes) and plot
4-
them to the same axes with hold "on". Then, toggle the visible property of
4+
them to the same axes. Then, toggle the visible property of
55
them using keypress event handling
66
77
If you want two images with different shapes to be plotted with the same
@@ -27,7 +27,7 @@
2727
# them to be resampled into the same axes space
2828
extent = (0, 1, 0, 1)
2929
im1 = plt.imshow(x1, extent=extent)
30-
im2 = plt.imshow(x2, extent=extent, hold=True)
30+
im2 = plt.imshow(x2, extent=extent)
3131
im2.set_visible(False)
3232

3333

examples/user_interfaces/embedding_in_qt4.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ class MyMplCanvas(FigureCanvas):
3333
def __init__(self, parent=None, width=5, height=4, dpi=100):
3434
fig = Figure(figsize=(width, height), dpi=dpi)
3535
self.axes = fig.add_subplot(111)
36-
# We want the axes cleared every time plot() is called
37-
self.axes.hold(False)
3836

3937
self.compute_initial_figure()
4038

41-
#
4239
FigureCanvas.__init__(self, fig)
4340
self.setParent(parent)
4441

@@ -75,7 +72,7 @@ def compute_initial_figure(self):
7572
def update_figure(self):
7673
# Build a list of 4 random integers between 0 and 10 (both inclusive)
7774
l = [random.randint(0, 10) for i in range(4)]
78-
75+
self.axes.cla()
7976
self.axes.plot([0, 1, 2, 3], l, 'r')
8077
self.draw()
8178

examples/user_interfaces/embedding_in_qt5.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ class MyMplCanvas(FigureCanvas):
3232
def __init__(self, parent=None, width=5, height=4, dpi=100):
3333
fig = Figure(figsize=(width, height), dpi=dpi)
3434
self.axes = fig.add_subplot(111)
35-
# We want the axes cleared every time plot() is called
36-
self.axes.hold(False)
3735

3836
self.compute_initial_figure()
3937

40-
#
4138
FigureCanvas.__init__(self, fig)
4239
self.setParent(parent)
4340

@@ -74,7 +71,7 @@ def compute_initial_figure(self):
7471
def update_figure(self):
7572
# Build a list of 4 random integers between 0 and 10 (both inclusive)
7673
l = [random.randint(0, 10) for i in range(4)]
77-
74+
self.axes.cla()
7875
self.axes.plot([0, 1, 2, 3], l, 'r')
7976
self.draw()
8077

0 commit comments

Comments
 (0)