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

Skip to content

Commit eb879a9

Browse files
committed
Make subplot_adjust work and remove work
1 parent 1b7bdfa commit eb879a9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/matplotlib/colorbar.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,15 @@ def __init__(self, parent, userax=True):
260260
self.outer_ax.tick_params = self.inner_ax.tick_params
261261
self.outer_ax.set_xticks = self.inner_ax.set_xticks
262262
self.outer_ax.set_yticks = self.inner_ax.set_yticks
263-
for attr in ["get_position", "set_position", "set_aspect"]:
263+
for attr in ["get_position", "set_aspect",
264+
"_remove_method", "_set_position",
265+
"set_position"]:
264266
setattr(self, attr, getattr(self.outer_ax, attr))
265267
self._colorbar_info = None # used for mpl-created axes
268+
if hasattr(self.outer_ax, "get_subplotspec"):
269+
attr = "get_subplotspec"
270+
setattr(self, attr, getattr(self.outer_ax, attr))
271+
266272
if userax:
267273
self._colorbar_info = 'user'
268274
# point the parent's methods all at this axes...
@@ -279,6 +285,7 @@ def draw(self, renderer):
279285
self.outer_ax.draw(renderer)
280286

281287

288+
282289
class _ColorbarSpine(mspines.Spine):
283290
def __init__(self, axes):
284291
self._ax = axes
@@ -954,12 +961,11 @@ def set_alpha(self, alpha):
954961
def remove(self):
955962
"""
956963
Remove this colorbar from the figure.
957-
964+
958965
If the colorbar was created with ``use_gridspec=True`` the previous
959966
gridspec is restored.
960967
"""
961-
self.ax.inner_ax.remove()
962-
self.ax.outer_ax.remove()
968+
self.ax.remove()
963969

964970
self.mappable.callbacksSM.disconnect(self.mappable.colorbar_cid)
965971
self.mappable.colorbar = None

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
12001200
"disabling constrained_layout.")
12011201
self.subplotpars.update(left, bottom, right, top, wspace, hspace)
12021202
for ax in self.axes:
1203-
if isinstance(ax, SubplotBase):
1203+
if hasattr(ax, 'get_subplotspec'):
12041204
ax._set_position(ax.get_subplotspec().get_position(self))
12051205
self.stale = True
12061206

0 commit comments

Comments
 (0)