@@ -917,7 +917,7 @@ def add_axes(self, *args, **kwargs):
917917
918918 self ._axstack .add (key , a )
919919 self .sca (a )
920- a ._remove_method = lambda ax : self .delaxes ( ax )
920+ a ._remove_method = self .__remove_ax
921921 self .stale = True
922922 a .stale_callback = _stale_figure_callback
923923 return a
@@ -1007,7 +1007,7 @@ def add_subplot(self, *args, **kwargs):
10071007
10081008 self ._axstack .add (key , a )
10091009 self .sca (a )
1010- a ._remove_method = lambda ax : self .delaxes ( ax )
1010+ a ._remove_method = self .__remove_ax
10111011 self .stale = True
10121012 a .stale_callback = _stale_figure_callback
10131013 return a
@@ -1144,6 +1144,32 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
11441144 # Returned axis array will be always 2-d, even if nrows=ncols=1.
11451145 return axarr
11461146
1147+ def __remove_ax (self , ax ):
1148+ def _reset_loc_form (axis ):
1149+ axis .set_major_formatter (axis .get_major_formatter ())
1150+ axis .set_major_locator (axis .get_major_locator ())
1151+ axis .set_minor_formatter (axis .get_minor_formatter ())
1152+ axis .set_minor_locator (axis .get_minor_locator ())
1153+
1154+ def _break_share_link (ax , grouper ):
1155+ siblings = grouper .get_siblings (ax )
1156+ if len (siblings ) > 1 :
1157+ grouper .remove (ax )
1158+ for last_ax in siblings :
1159+ if ax is last_ax :
1160+ continue
1161+ return last_ax
1162+ return None
1163+
1164+ self .delaxes (ax )
1165+ last_ax = _break_share_link (ax , ax ._shared_y_axes )
1166+ if last_ax is not None :
1167+ _reset_loc_form (last_ax .yaxis )
1168+
1169+ last_ax = _break_share_link (ax , ax ._shared_x_axes )
1170+ if last_ax is not None :
1171+ _reset_loc_form (last_ax .xaxis )
1172+
11471173 def clf (self , keep_observers = False ):
11481174 """
11491175 Clear the figure.
0 commit comments