Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix twin remove #5682

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 5 commits into from
Dec 15, 2015
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
FIX/ENH: do more clean up when removing axes
This adds clean up of the shared axes `Grouper` objects as part
of removing an axes.

`_reset_loc_form` is required because the locator/formatters end up
bound to the axis objects of the last axes object (all of the Axes in
the group share the same formatter/locator objects but have different
Axis objects so that all but one of the Axis objects can be made not
visible to not over-draw).  If these are not re-bound to a still visible
axes then changing the limits will change the view limits, but not the
tick locations.

closes #5663
  • Loading branch information
tacaswell committed Dec 15, 2015
commit 0245db95ee5fb23271f1a68e979f7893070fd0ab
30 changes: 28 additions & 2 deletions 30 lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def add_axes(self, *args, **kwargs):

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
a._remove_method = self.__remove_ax
self.stale = True
a.stale_callback = _stale_figure_callback
return a
Expand Down Expand Up @@ -1006,11 +1006,37 @@ def add_subplot(self, *args, **kwargs):

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
a._remove_method = self.__remove_ax
self.stale = True
a.stale_callback = _stale_figure_callback
return a

def __remove_ax(self, ax):
def _reset_loc_form(axis):
axis.set_major_formatter(axis.get_major_formatter())
axis.set_major_locator(axis.get_major_locator())
axis.set_minor_formatter(axis.get_minor_formatter())
axis.set_minor_locator(axis.get_minor_locator())

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 last_ax:
continue
return last_ax
return None

self.delaxes(ax)
last_ax = _break_share_link(ax, ax._shared_y_axes)
if last_ax is not None:
_reset_loc_form(last_ax.yaxis)

last_ax = _break_share_link(ax, ax._shared_x_axes)
if last_ax is not None:
_reset_loc_form(last_ax.xaxis)

def clf(self, keep_observers=False):
"""
Clear the figure.
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.