Skip to content

Commit 65a10b9

Browse files
committed
Deprecate "hold" kwarg and machinery.
1 parent fc204fa commit 65a10b9

File tree

9 files changed

+505
-251
lines changed

9 files changed

+505
-251
lines changed

boilerplate.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@
5050
@_autogen_docstring(Axes.%(func)s)
5151
def %(func)s(%(argspec)s):
5252
%(ax)s = gca()
53-
# allow callers to override the hold state by passing hold=True|False
54-
%(washold)s = %(ax)s.ishold()
53+
# Deprecated: allow callers to override the hold state
54+
# by passing hold=True|False
55+
%(washold)s = %(ax)s._hold
5556
%(sethold)s
5657
if hold is not None:
57-
%(ax)s.hold(hold)
58+
%(ax)s._hold = hold
59+
from matplotlib.cbook import mplDeprecation
60+
warnings.warn("The 'hold' kwarg is deprecated since 2.0.",
61+
mplDeprecation)
5862
try:
5963
%(ret)s = %(ax)s.%(func)s(%(call)s)
6064
finally:
61-
%(ax)s.hold(%(washold)s)
65+
%(ax)s._hold = %(washold)s
6266
%(mappable)s
6367
return %(ret)s
6468
"""

lib/matplotlib/axes/_axes.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ def acorr(self, x, **kwargs):
16651665
16661666
x : sequence of scalar
16671667
1668-
hold : boolean, optional, default: True
1668+
hold : boolean, optional, *deprecated*, default: True
16691669
16701670
detrend : callable, optional, default: `mlab.detrend_none`
16711671
x is detrended by the `detrend` callable. Default is no
@@ -1713,6 +1713,8 @@ def acorr(self, x, **kwargs):
17131713
.. plot:: mpl_examples/pylab_examples/xcorr_demo.py
17141714
17151715
"""
1716+
if "hold" in kwargs:
1717+
warnings.warn("the 'hold' kwarg is deprecated", mplDeprecation)
17161718
return self.xcorr(x, x, **kwargs)
17171719

17181720
@unpack_labeled_data(replace_names=["x", "y"], label_namer="y")
@@ -1730,7 +1732,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
17301732
17311733
y : sequence of scalars of length n
17321734
1733-
hold : boolean, optional, default: True
1735+
hold : boolean, optional, *deprecated*, default: True
17341736
17351737
detrend : callable, optional, default: `mlab.detrend_none`
17361738
x is detrended by the `detrend` callable. Default is no
@@ -1769,6 +1771,8 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
17691771
The cross correlation is performed with :func:`numpy.correlate` with
17701772
`mode` = 2.
17711773
"""
1774+
if "hold" in kwargs:
1775+
warnings.warn("the 'hold' kwarg is deprecated", mplDeprecation)
17721776

17731777
Nx = len(x)
17741778
if Nx != len(y):
@@ -2136,7 +2140,7 @@ def make_iterable(x):
21362140
patches.append(r)
21372141

21382142
holdstate = self._hold
2139-
self.hold(True) # ensure hold is on before plotting errorbars
2143+
self._hold = True # ensure hold is on before plotting errorbars
21402144

21412145
if xerr is not None or yerr is not None:
21422146
if orientation == 'vertical':
@@ -2158,7 +2162,7 @@ def make_iterable(x):
21582162
else:
21592163
errorbar = None
21602164

2161-
self.hold(holdstate) # restore previous hold state
2165+
self._hold = holdstate # restore previous hold state
21622166

21632167
if adjust_xlim:
21642168
xmin, xmax = self.dataLim.intervalx
@@ -2380,7 +2384,7 @@ def stem(self, *args, **kwargs):
23802384
remember_hold = self._hold
23812385
if not self._hold:
23822386
self.cla()
2383-
self.hold(True)
2387+
self._hold = True
23842388

23852389
# Assume there's at least one data array
23862390
y = np.asarray(args[0])
@@ -2464,7 +2468,7 @@ def stem(self, *args, **kwargs):
24642468
color=basecolor, linestyle=basestyle,
24652469
marker=basemarker, label="_nolegend_")
24662470

2467-
self.hold(remember_hold)
2471+
self._hold = remember_hold
24682472

24692473
stem_container = StemContainer((markerline, stemlines, baseline),
24702474
label=label)
@@ -3786,7 +3790,7 @@ def dopatch(xs, ys, **kwargs):
37863790
setlabels(datalabels)
37873791

37883792
# reset hold status
3789-
self.hold(holdStatus)
3793+
self._hold=holdStatus
37903794

37913795
return dict(whiskers=whiskers, caps=caps, boxes=boxes,
37923796
medians=medians, fliers=fliers, means=means)

lib/matplotlib/axes/_base.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1191,14 +1191,25 @@ def set_color_cycle(self, clist):
11911191
else:
11921192
self.set_prop_cycle('color', clist)
11931193

1194+
@cbook.deprecated("2.0")
11941195
def ishold(self):
1195-
"""return the HOLD status of the axes"""
1196+
"""return the HOLD status of the axes
1197+
1198+
The `hold` mechanism is deprecated and will be removed in
1199+
v3.0.
1200+
"""
1201+
11961202
return self._hold
11971203

1204+
@cbook.deprecated("2.0")
11981205
def hold(self, b=None):
11991206
"""
12001207
Set the hold state
12011208
1209+
The ``hold`` mechanism is deprecated and will be removed in
1210+
v3.0. The behavior will remain consistent with the
1211+
long-time default value of True.
1212+
12021213
If *hold* is *None* (default), toggle the *hold* state. Else
12031214
set the *hold* state to boolean value *b*.
12041215
@@ -1223,6 +1234,7 @@ def hold(self, b=None):
12231234
else:
12241235
self._hold = b
12251236

1237+
12261238
def get_aspect(self):
12271239
return self._aspect
12281240

lib/matplotlib/colorbar.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,10 @@ def _add_solids(self, X, Y, C):
501501
# Save, set, and restore hold state to keep pcolor from
502502
# clearing the axes. Ordinarily this will not be needed,
503503
# since the axes object should already have hold set.
504-
_hold = self.ax.ishold()
505-
self.ax.hold(True)
504+
_hold = self.ax._hold
505+
self.ax._hold = True
506506
col = self.ax.pcolormesh(*args, **kw)
507-
self.ax.hold(_hold)
507+
self.ax._hold = _hold
508508
#self.add_observer(col) # We should observe, not be observed...
509509

510510
if self.solids is not None:
@@ -1262,8 +1262,8 @@ def _add_solids(self, X, Y, C):
12621262
# Save, set, and restore hold state to keep pcolor from
12631263
# clearing the axes. Ordinarily this will not be needed,
12641264
# since the axes object should already have hold set.
1265-
_hold = self.ax.ishold()
1266-
self.ax.hold(True)
1265+
_hold = self.ax._hold
1266+
self.ax._hold = True
12671267

12681268
kw = {'alpha': self.alpha, }
12691269

@@ -1309,7 +1309,7 @@ def _add_solids(self, X, Y, C):
13091309
linewidths=(0.5 * mpl.rcParams['axes.linewidth'],))
13101310
self.ax.add_collection(self.dividers)
13111311

1312-
self.ax.hold(_hold)
1312+
self.ax._hold = _hold
13131313

13141314

13151315
def colorbar_factory(cax, mappable, **kwargs):

lib/matplotlib/figure.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ def set_canvas(self, canvas):
569569
"""
570570
self.canvas = canvas
571571

572+
@cbook.deprecated("2.0")
572573
def hold(self, b=None):
573574
"""
574575
Set the hold state. If hold is None (default), toggle the
@@ -579,6 +580,8 @@ def hold(self, b=None):
579580
hold() # toggle hold
580581
hold(True) # hold is on
581582
hold(False) # hold is off
583+
584+
All "hold" machinery is deprecated.
582585
"""
583586
if b is None:
584587
self._hold = not self._hold
@@ -1591,7 +1594,7 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
15911594
cax, kw = cbar.make_axes_gridspec(ax, **kw)
15921595
else:
15931596
cax, kw = cbar.make_axes(ax, **kw)
1594-
cax.hold(True)
1597+
cax._hold = True
15951598
cb = cbar.colorbar_factory(cax, mappable, **kw)
15961599

15971600
self.sca(current_ax)

lib/matplotlib/pylab.py

-2
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@
4949
getp - get a graphics property
5050
grid - set whether gridding is on
5151
hist - make a histogram
52-
hold - set the axes hold state
5352
ioff - turn interaction mode off
5453
ion - turn interaction mode on
5554
isinteractive - return True if interaction mode is on
5655
imread - load image file into array
5756
imsave - save array as an image file
5857
imshow - plot image data
59-
ishold - return the hold state of the current axes
6058
legend - make an axes legend
6159
locator_params - adjust parameters used in locating axis ticks
6260
loglog - a log log plot

0 commit comments

Comments
 (0)