@@ -916,7 +916,7 @@ def add_axes(self, *args, **kwargs):
916916
917917 self ._axstack .add (key , a )
918918 self .sca (a )
919- a ._remove_method = lambda ax : self .delaxes ( ax )
919+ a ._remove_method = self .__remove_ax
920920 self .stale = True
921921 a .stale_callback = _stale_figure_callback
922922 return a
@@ -1006,11 +1006,37 @@ def add_subplot(self, *args, **kwargs):
10061006
10071007 self ._axstack .add (key , a )
10081008 self .sca (a )
1009- a ._remove_method = lambda ax : self .delaxes ( ax )
1009+ a ._remove_method = self .__remove_ax
10101010 self .stale = True
10111011 a .stale_callback = _stale_figure_callback
10121012 return a
10131013
1014+ def __remove_ax (self , ax ):
1015+ def _reset_loc_form (axis ):
1016+ axis .set_major_formatter (axis .get_major_formatter ())
1017+ axis .set_major_locator (axis .get_major_locator ())
1018+ axis .set_minor_formatter (axis .get_minor_formatter ())
1019+ axis .set_minor_locator (axis .get_minor_locator ())
1020+
1021+ def _break_share_link (ax , grouper ):
1022+ siblings = grouper .get_siblings (ax )
1023+ if len (siblings ) > 1 :
1024+ grouper .remove (ax )
1025+ for last_ax in siblings :
1026+ if ax is last_ax :
1027+ continue
1028+ return last_ax
1029+ return None
1030+
1031+ self .delaxes (ax )
1032+ last_ax = _break_share_link (ax , ax ._shared_y_axes )
1033+ if last_ax is not None :
1034+ _reset_loc_form (last_ax .yaxis )
1035+
1036+ last_ax = _break_share_link (ax , ax ._shared_x_axes )
1037+ if last_ax is not None :
1038+ _reset_loc_form (last_ax .xaxis )
1039+
10141040 def clf (self , keep_observers = False ):
10151041 """
10161042 Clear the figure.
0 commit comments