diff --git a/doc/api/next_api_changes/2019-01-04-SH.rst b/doc/api/next_api_changes/2019-01-04-SH.rst new file mode 100644 index 000000000000..147b7009c36d --- /dev/null +++ b/doc/api/next_api_changes/2019-01-04-SH.rst @@ -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 `_), 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. diff --git a/lib/mpl_toolkits/axes_grid1/parasite_axes.py b/lib/mpl_toolkits/axes_grid1/parasite_axes.py index 900dac19a8b1..d1b27974af59 100644 --- a/lib/mpl_toolkits/axes_grid1/parasite_axes.py +++ b/lib/mpl_toolkits/axes_grid1/parasite_axes.py @@ -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): """ @@ -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): """ @@ -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 diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axes_grid1/twin_axes_empty_and_removed.png b/lib/mpl_toolkits/tests/baseline_images/test_axes_grid1/twin_axes_empty_and_removed.png index 096104fa0533..7dce51c7bef7 100644 Binary files a/lib/mpl_toolkits/tests/baseline_images/test_axes_grid1/twin_axes_empty_and_removed.png and b/lib/mpl_toolkits/tests/baseline_images/test_axes_grid1/twin_axes_empty_and_removed.png differ