From 973fe811c5fcf5b1f7c5d3592988897ddb1e0e3e Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Fri, 25 Nov 2016 13:46:59 -1000 Subject: [PATCH] Begin deprecation of "hold": remove from examples --- examples/pylab_examples/contour_image.py | 28 +++++++++----------- examples/pylab_examples/contourf_demo.py | 6 ++--- examples/pylab_examples/layer_images.py | 1 - examples/pylab_examples/scatter_masked.py | 2 +- examples/pylab_examples/toggle_images.py | 4 +-- examples/user_interfaces/embedding_in_qt4.py | 5 +--- examples/user_interfaces/embedding_in_qt5.py | 5 +--- 7 files changed, 20 insertions(+), 31 deletions(-) diff --git a/examples/pylab_examples/contour_image.py b/examples/pylab_examples/contour_image.py index 71b853c154cd..e38119afe999 100755 --- a/examples/pylab_examples/contour_image.py +++ b/examples/pylab_examples/contour_image.py @@ -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) @@ -46,11 +47,12 @@ # 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') @@ -58,21 +60,17 @@ # 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'") @@ -80,8 +78,7 @@ 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'") @@ -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() diff --git a/examples/pylab_examples/contourf_demo.py b/examples/pylab_examples/contourf_demo.py index 21448f99d7d6..20a17c85191c 100755 --- a/examples/pylab_examples/contourf_demo.py +++ b/examples/pylab_examples/contourf_demo.py @@ -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 @@ -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') @@ -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) diff --git a/examples/pylab_examples/layer_images.py b/examples/pylab_examples/layer_images.py index a862ac045163..1a8675c2bb06 100644 --- a/examples/pylab_examples/layer_images.py +++ b/examples/pylab_examples/layer_images.py @@ -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) diff --git a/examples/pylab_examples/scatter_masked.py b/examples/pylab_examples/scatter_masked.py index 5ceb26d2711b..77c1c6299208 100644 --- a/examples/pylab_examples/scatter_masked.py +++ b/examples/pylab_examples/scatter_masked.py @@ -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) diff --git a/examples/pylab_examples/toggle_images.py b/examples/pylab_examples/toggle_images.py index 3e7f7e6127e7..f193a9f3f3ad 100644 --- a/examples/pylab_examples/toggle_images.py +++ b/examples/pylab_examples/toggle_images.py @@ -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 @@ -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) diff --git a/examples/user_interfaces/embedding_in_qt4.py b/examples/user_interfaces/embedding_in_qt4.py index 31108c9bd300..cef8369344f4 100755 --- a/examples/user_interfaces/embedding_in_qt4.py +++ b/examples/user_interfaces/embedding_in_qt4.py @@ -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) @@ -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() diff --git a/examples/user_interfaces/embedding_in_qt5.py b/examples/user_interfaces/embedding_in_qt5.py index 95059c62b378..8d2cbce51b18 100755 --- a/examples/user_interfaces/embedding_in_qt5.py +++ b/examples/user_interfaces/embedding_in_qt5.py @@ -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) @@ -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()