Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7fc7cd6

Browse files
committed
FIX: add cla to colorbar
co-author: Greg Lucas <[email protected]>
1 parent c56e3c5 commit 7fc7cd6

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

lib/matplotlib/colorbar.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ def __init__(self, parent, userax=True):
260260
parent.remove()
261261
else:
262262
outer_ax = parent
263-
264263
inner_ax = outer_ax.inset_axes([0, 0, 1, 1])
265264
self.__dict__.update(inner_ax.__dict__)
266265

@@ -285,6 +284,32 @@ def _set_inner_bounds(self, bounds):
285284
self.inner_ax._axes_locator = _TransformedBoundsLocator(
286285
bounds, self.outer_ax.transAxes)
287286

287+
def cla(self):
288+
"""
289+
Reset the colorbar axes to be empty.
290+
"""
291+
# need to low-level manipulate the stacks because we
292+
# are just swapping places here. We don't need to
293+
# set transforms etc...
294+
self.inner_ax.cla()
295+
self.outer_ax.cla()
296+
self.figure._axstack.add(self)
297+
self.figure._axstack.remove(self.outer_ax)
298+
self.figure._localaxes.add(self)
299+
self.figure._localaxes.remove(self.outer_ax)
300+
301+
self.__dict__.update(self.outer_ax.__dict__)
302+
self.inner_ax.remove()
303+
del self.inner_ax
304+
del self.outer_ax
305+
306+
self.xaxis.set_visible(True)
307+
self.yaxis.set_visible(True)
308+
for spine in self.spines.values():
309+
spine.set_visible(True)
310+
311+
self.set_facecolor(mpl.rcParams['axes.facecolor'])
312+
288313

289314
class _ColorbarSpine(mspines.Spine):
290315
def __init__(self, axes):
@@ -1250,7 +1275,12 @@ def update_normal(self, mappable):
12501275
self.norm = mappable.norm
12511276
self._reset_locator_formatter_scale()
12521277

1253-
self.draw_all()
1278+
try:
1279+
self.draw_all()
1280+
except AttributeError:
1281+
# update_normal sometimes is called when it shouldn't be..
1282+
pass
1283+
12541284
if isinstance(self.mappable, contour.ContourSet):
12551285
CS = self.mappable
12561286
if not CS.filled:

0 commit comments

Comments
 (0)