Skip to content

Begin deprecation of "hold": remove from examples #7515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions examples/pylab_examples/contour_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
cmap = cm.PRGn

plt.figure()
fig = plt.figure()
fig.subplots_adjust(hspace=0.3)


plt.subplot(2, 2, 1)
Expand All @@ -46,42 +47,38 @@
# contour separately; don't try to change the edgecolor or edgewidth
# of the polygons in the collections returned by contourf.
# Use levels output from previous call to guarantee they are the same.
cset2 = plt.contour(X, Y, Z, cset1.levels,
colors='k',
hold='on')

cset2 = plt.contour(X, Y, Z, cset1.levels, colors='k')

# We don't really need dashed contour lines to indicate negative
# regions, so let's turn them off.

for c in cset2.collections:
c.set_linestyle('solid')

# It is easier here to make a separate call to contour than
# to set up an array of colors and linewidths.
# We are making a thick green line as a zero contour.
# Specify the zero level as a tuple with only 0 in it.
cset3 = plt.contour(X, Y, Z, (0,),
colors='g',
linewidths=2,
hold='on')

cset3 = plt.contour(X, Y, Z, (0,), colors='g', linewidths=2)
plt.title('Filled contours')
plt.colorbar(cset1)
#hot()


plt.subplot(2, 2, 2)

plt.imshow(Z, extent=extent, cmap=cmap, norm=norm)
v = plt.axis()
plt.contour(Z, levels, hold='on', colors='k',
origin='upper', extent=extent)
plt.contour(Z, levels, colors='k', origin='upper', extent=extent)
plt.axis(v)
plt.title("Image, origin 'upper'")

plt.subplot(2, 2, 3)

plt.imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
v = plt.axis()
plt.contour(Z, levels, hold='on', colors='k',
origin='lower', extent=extent)
plt.contour(Z, levels, colors='k', origin='lower', extent=extent)
plt.axis(v)
plt.title("Image, origin 'lower'")

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

plt.show()
6 changes: 3 additions & 3 deletions examples/pylab_examples/contourf_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
interior = np.sqrt((X**2) + (Y**2)) < 0.5
Z[interior] = np.ma.masked


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

CS2 = plt.contour(CS, levels=CS.levels[::2],
colors='r',
origin=origin,
hold='on')
origin=origin)

plt.title('Nonsense (3 masked regions)')
plt.xlabel('word length anomaly')
Expand Down Expand Up @@ -97,6 +95,8 @@
# cmap.set_bad("red")

fig, axs = plt.subplots(2, 2)
fig.subplots_adjust(hspace=0.3)

for ax, extend in zip(axs.ravel(), extends):
cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend, origin=origin)
fig.colorbar(cs, ax=ax, shrink=0.9)
Expand Down
1 change: 0 additions & 1 deletion examples/pylab_examples/layer_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def func3(x, y):
Z1.shape = (8, 8) # chessboard
im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
extent=extent)
plt.hold(True)

Z2 = func3(X, Y)

Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/scatter_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
r = np.sqrt(x*x + y*y)
area1 = np.ma.masked_where(r < r0, area)
area2 = np.ma.masked_where(r >= r0, area)
plt.scatter(x, y, s=area1, marker='^', c=c, hold='on')
plt.scatter(x, y, s=area1, marker='^', c=c)
plt.scatter(x, y, s=area2, marker='o', c=c)
# Show the boundary between the regions:
theta = np.arange(0, np.pi/2, 0.01)
Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/toggle_images.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" toggle between two images by pressing "t"

The basic idea is to load two images (they can be different shapes) and plot
them to the same axes with hold "on". Then, toggle the visible property of
them to the same axes. Then, toggle the visible property of
them using keypress event handling

If you want two images with different shapes to be plotted with the same
Expand All @@ -27,7 +27,7 @@
# them to be resampled into the same axes space
extent = (0, 1, 0, 1)
im1 = plt.imshow(x1, extent=extent)
im2 = plt.imshow(x2, extent=extent, hold=True)
im2 = plt.imshow(x2, extent=extent)
im2.set_visible(False)


Expand Down
5 changes: 1 addition & 4 deletions examples/user_interfaces/embedding_in_qt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ class MyMplCanvas(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.compute_initial_figure()

#
FigureCanvas.__init__(self, fig)
self.setParent(parent)

Expand Down Expand Up @@ -75,7 +72,7 @@ def compute_initial_figure(self):
def update_figure(self):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
l = [random.randint(0, 10) for i in range(4)]

self.axes.cla()
self.axes.plot([0, 1, 2, 3], l, 'r')
self.draw()

Expand Down
5 changes: 1 addition & 4 deletions examples/user_interfaces/embedding_in_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ class MyMplCanvas(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.compute_initial_figure()

#
FigureCanvas.__init__(self, fig)
self.setParent(parent)

Expand Down Expand Up @@ -74,7 +71,7 @@ def compute_initial_figure(self):
def update_figure(self):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
l = [random.randint(0, 10) for i in range(4)]

self.axes.cla()
self.axes.plot([0, 1, 2, 3], l, 'r')
self.draw()

Expand Down