8000 Deal with axes_grid differences · matplotlib/matplotlib@c2cf781 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2cf781

Browse files
committed
Deal with axes_grid differences
1 parent f084fcb commit c2cf781

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

lib/matplotlib/colorbar.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,19 @@ def __init__(self, parent, userax=True):
239239
parent._axes.add_child_axes(outer_ax)
240240
outer_ax._axes.child_axes.remove(parent)
241241
else:
242-
parent.remove()
242+
try:
243+
parent.remove()
244+
except ValueError:
245+
pass # Already removed
243246
else:
244247
outer_ax = parent
245248

246-
# swap axes in the stack:
247-
fig._localaxes.remove(outer_ax)
248-
fig._axstack.remove(outer_ax)
249-
fig._localaxes.add(self)
250-
fig._axstack.add(self)
249+
# swap axes in the stack if its in there:
250+
if outer_ax in fig._localaxes:
251+
fig._localaxes.remove(outer_ax)
252+
fig._axstack.remove(outer_ax)
253+
fig._localaxes.add(self)
254+
fig._axstack.add(self)
251255
inner_ax = outer_ax.inset_axes([0, 0, 1, 1])
252256
self.__dict__.update(inner_ax.__dict__)
253257

@@ -262,7 +266,7 @@ def __init__(self, parent, userax=True):
262266
self.outer_ax.set_yticks = self.inner_ax.set_yticks
263267
for attr in ["get_position", "set_aspect",
264268
"_remove_method", "_set_position",
265-
"set_position"]:
269+
"set_position", "cla", "draw"]:
266270
setattr(self, attr, getattr(self.outer_ax, attr))
267271
self._colorbar_info = None # used for mpl-created axes
268272
if hasattr(self.outer_ax, "get_subplotspec"):
@@ -272,7 +276,12 @@ def __init__(self, parent, userax=True):
272276
if userax:
273277
self._colorbar_info = 'user'
274278
# point the parent's methods all at this axes...
279+
origdict = parent.__dict__
275280
parent.__dict__ = self.__dict__
281+
for key in origdict.keys():
282+
if key not in parent.__dict__:
283+
parent.__dict__[key] = origdict[key]
284+
276285

277286
def _set_inner_bounds(self, bounds):
278287
"""
@@ -281,9 +290,6 @@ def _set_inner_bounds(self, bounds):
281290
self.inner_ax._axes_locator = _TransformedBoundsLocator(
282291
bounds, self.outer_ax.transAxes)
283292

284-
def draw(self, renderer):
285-
self.outer_ax.draw(renderer)
286-
287293

288294
class _ColorbarSpine(mspines.Spine):
289295
def __init__(self, axes):

lib/matplotlib/testing/decorators.py

Lines changed: 1 addition & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def remove_ticks(ax):
127127
for child in ax.child_axes:
128128
remove_ticks(child)
129129
for ax in figure.get_axes():
130+
print('Remove', ax)
130131
remove_ticks(ax)
131132

132133

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,23 @@ def __init__(self, *args, orientation, **kwargs):
2525
self._locator = None # deprecated.
2626
super().__init__(*args, **kwargs)
2727

28+
#@_api.deprecated("3.5", alternative="fig.colorbar(im, cax=ax.cax)")
2829
def colorbar(self, mappable, *, ticks=None, **kwargs):
2930
orientation = (
3031
"horizontal" if self.orientation in ["top", "bottom"] else
3132
"vertical")
32-
kwargs['userax'] = False
33-
cb = mpl.colorbar.Colorbar(
34-
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
35-
self._config_axes()
33+
cb = self.figure.colorbar(mappable, cax=self, orientation=orientation, ticks=ticks, **kwargs)
3634
return cb
3735

38-
def _config_axes(self):
39-
"""Make an axes patch and outline."""
40-
ax = self
41-
ax.set_navigate(False)
42-
ax.axis[:].toggle(all=False)
43-
b = self._default_label_on
44-
ax.axis[self.orientation].toggle(all=b)
45-
4636
def toggle_label(self, b):
4737
self._default_label_on = b
4838
axis = self.axis[self.orientation]
4939
axis.toggle(ticklabels=b, label=b)
5040

5141
def cla(self):
42+
orientation = self.orientation
5243
super().cla()
53-
self._config_axes()
44+
self.orientation = orientation
5445

5546

5647
class CbarAxes(CbarAxesBase, Axes):

0 commit comments

Comments
 (0)
0