Skip to content

[WIP] axes_grid1: make twin* not modify host axes #13092

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions doc/api/next_api_changes/2019-01-04-SH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Changes to ``twin*`` methods in `mpl_toolkits.axes_grid1`
-----------------------------------------------------------

Previously, calling `~mpl_toolkits.axes_grid1.parasite_axes.HostAxesBase.twin`,
`~mpl_toolkits.axes_grid1.parasite_axes.HostAxesBase.twinx` or
`~mpl_toolkits.axes_grid1.parasite_axes.HostAxesBase.twiny` on
`mpl_toolkits.axes_grid1` host axes would hide the host axes' own axis
lines so that there is no overdrawing with the twin/parasite axes' axis lines.
This could lead to surprising behavior in certain cases
(`#10748 <https://github.com/matplotlib/matplotlib/issues/10748>`_), so the
logic has now been reversed, such that host axis lines are kept visible and
twin/parasite axis lines are hidden. This may break code which relies on the
specifics of host/parasite axis line visibility.
18 changes: 6 additions & 12 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,15 @@ def twinx(self, axes_class=None):
self.parasites.append(ax2)
ax2._remove_method = self._remove_twinx

self.axis["right"].set_visible(False)

ax2.axis["right"].set_visible(True)
ax2.axis["right"].toggle(all=True)
ax2.axis["right"].line.set_visible(False)
ax2.axis["left", "top", "bottom"].set_visible(False)

return ax2

def _remove_twinx(self, ax):
self.parasites.remove(ax)
self.axis["right"].set_visible(True)
self.axis["right"].toggle(ticklabels=False, label=False)

def twiny(self, axes_class=None):
"""
Expand All @@ -278,17 +276,15 @@ def twiny(self, axes_class=None):
self.parasites.append(ax2)
ax2._remove_method = self._remove_twiny

self.axis["top"].set_visible(False)

ax2.axis["top"].set_visible(True)
ax2.axis["top"].toggle(all=True)
ax2.axis["top"].line.set_visible(False)
ax2.axis["left", "right", "bottom"].set_visible(False)

return ax2

def _remove_twiny(self, ax):
self.parasites.remove(ax)
self.axis["top"].set_visible(True)
self.axis["top"].toggle(ticklabels=False, label=False)

def twin(self, aux_trans=None, axes_class=None):
"""
Expand All @@ -313,15 +309,13 @@ def twin(self, aux_trans=None, axes_class=None):
self.parasites.append(ax2)
ax2._remove_method = self.parasites.remove

self.axis["top", "right"].set_visible(False)

ax2.axis["top", "right"].set_visible(True)
ax2.axis["top", "right"].toggle(all=True)
ax2.axis["top", "right"].line.set_visible(False)
ax2.axis["left", "bottom"].set_visible(False)

def _remove_method(h):
self.parasites.remove(h)
self.axis["top", "right"].set_visible(True)
self.axis["top", "right"].toggle(ticklabels=False, label=False)
ax2._remove_method = _remove_method

return ax2
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.