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

Skip to content

Commit aaaee32

Browse files
committed
FIX: colorbarAxes properly in the axes stack
1 parent 3cf46cb commit aaaee32

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/matplotlib/colorbar.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def __init__(self, parent, userax=True):
245245
True if the user passed `.Figure.colorbar` the axes manually.
246246
"""
247247

248+
fig = parent.figure
248249
if userax:
249250
# copy position:
250-
fig = parent.figure
251251
outer_ax = fig.add_axes(parent.get_position())
252252
# copy the locator if one exists:
253253
outer_ax._axes_locator = parent._axes_locator
@@ -261,11 +261,17 @@ def __init__(self, parent, userax=True):
261261
else:
262262
outer_ax = parent
263263

264+
# swap axes in the stack:
265+
fig._localaxes.remove(outer_ax)
266+
fig._axstack.remove(outer_ax)
267+
fig._localaxes.add(self)
268+
fig._axstack.add(self)
264269
inner_ax = outer_ax.inset_axes([0, 0, 1, 1])
265270
self.__dict__.update(inner_ax.__dict__)
266271

267272
self.outer_ax = outer_ax
268273
self.inner_ax = inner_ax
274+
269275
self.outer_ax.xaxis.set_visible(False)
270276
self.outer_ax.yaxis.set_visible(False)
271277
self.outer_ax.set_facecolor('none')
@@ -285,6 +291,9 @@ def _set_inner_bounds(self, bounds):
285291
self.inner_ax._axes_locator = _TransformedBoundsLocator(
286292
bounds, self.outer_ax.transAxes)
287293

294+
def draw(self, renderer):
295+
self.outer_ax.draw(renderer)
296+
288297

289298
class _ColorbarSpine(mspines.Spine):
290299
def __init__(self, axes):

0 commit comments

Comments
 (0)