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

Skip to content

Simplify delaxes. #26026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ def joined(self, a, b):
return (self._mapping.get(a, object()) is self._mapping.get(b))

def remove(self, a):
"""Remove *a* from the grouper, doing nothing if it is not there."""
set_a = self._mapping.pop(a, None)
if set_a:
set_a.remove(a)
Expand Down
42 changes: 16 additions & 26 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,38 +925,28 @@ def delaxes(self, ax):
Remove the `~.axes.Axes` *ax* from the figure; update the current Axes.
"""

def _reset_locators_and_formatters(axis):
# Set the formatters and locators to be associated with axis
# (where previously they may have been associated with another
# Axis instance)
axis.get_major_formatter().set_axis(axis)
axis.get_major_locator().set_axis(axis)
axis.get_minor_formatter().set_axis(axis)
axis.get_minor_locator().set_axis(axis)

def _break_share_link(ax, grouper):
siblings = grouper.get_siblings(ax)
if len(siblings) > 1:
grouper.remove(ax)
for last_ax in siblings:
if ax is not last_ax:
return last_ax
return None

self._axstack.remove(ax)
self._axobservers.process("_axes_change_event", self)
self.stale = True
self._localaxes.remove(ax)
self.canvas.release_mouse(ax)

# Break link between any shared axes
for name in ax._axis_names:
last_ax = _break_share_link(ax, ax._shared_axes[name])
if last_ax is not None:
_reset_locators_and_formatters(last_ax._axis_map[name])

# Break link between any twinned axes
_break_share_link(ax, ax._twinned_axes)
for name in ax._axis_names: # Break link between any shared axes
grouper = ax._shared_axes[name]
siblings = [other for other in grouper.get_siblings(ax) if other is not ax]
if not siblings: # Axes was not shared along this axis; we're done.
continue
grouper.remove(ax)
# Formatters and locators may previously have been associated with the now
# removed axis. Update them to point to an axis still there (we can pick
# any of them, and use the first sibling).
remaining_axis = siblings[0]._axis_map[name]
remaining_axis.get_major_formatter().set_axis(remaining_axis)
remaining_axis.get_major_locator().set_axis(remaining_axis)
remaining_axis.get_minor_formatter().set_axis(remaining_axis)
remaining_axis.get_minor_locator().set_axis(remaining_axis)

ax._twinned_axes.remove(ax) # Break link between any twinned axes.

def clear(self, keep_observers=False):
"""
Expand Down