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

Skip to content

Commit 2d25e62

Browse files
committed
axes_grid1: make twin* not modify host axes
PR #4898 changed the behavior of twinx() and twiny() in axes_grid1 to make them consistent with twin(). This commit inverts the "direction" of consistency and makes twin() behave like the pre-#4898 twinx() and twiny() instead. This way, the API becomes less surprising: instead of hiding certain host axes, twin* now keeps the host axes unmodified, while the parasite axes have their axis lines hidden instead. Unfortunately, this change breaks backwards-compatibility for code relying on the specifics of host and parasite axes visibility. Helps with #10748.
1 parent f7b88be commit 2d25e62

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

doc/api/api_changes.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ This pages lists API changes for the most recent version of Matplotlib.
3636
next_api_changes/*
3737

3838

39+
API Changes for 3.1.0
40+
=====================
41+
42+
Changes to ``twin*`` methods in `~.mpl_toolkits.axes_grid1`
43+
-----------------------------------------------------------
44+
45+
Previously, calling ``twin``, ``twinx`` and ``twiny`` on
46+
`~.mpl_toolkits.axes_grid1` host axes would hide the host axes' own axis lines
47+
so that there is no overdrawing with the twin/parasite axes' axis lines. This
48+
could lead to surprising behavior in certain cases
49+
([#10748](https://github.com/matplotlib/matplotlib/issues/10748)), so the
50+
logic has now been reversed. I.e., host axis lines are kept and twin/parasite
51+
axis lines hidden. This may break code which relies on the specifics of
52+
host/parasite axis line visibility.
53+
3954
API Changes for 3.0.1
4055
=====================
4156

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,15 @@ def twinx(self, axes_class=None):
249249
self.parasites.append(ax2)
250250
ax2._remove_method = self._remove_twinx
251251

252-
self.axis["right"].set_visible(False)
253-
254252
ax2.axis["right"].set_visible(True)
253+
ax2.axis["right"].toggle(all=True)
254+
ax2.axis["right"].line.set_visible(False)
255255
ax2.axis["left", "top", "bottom"].set_visible(False)
256256

257257
return ax2
258258

259259
def _remove_twinx(self, ax):
260260
self.parasites.remove(ax)
261-
self.axis["right"].set_visible(True)
262-
self.axis["right"].toggle(ticklabels=False, label=False)
263261

264262
def twiny(self, axes_class=None):
265263
"""
@@ -278,17 +276,15 @@ def twiny(self, axes_class=None):
278276
self.parasites.append(ax2)
279277
ax2._remove_method = self._remove_twiny
280278

281-
self.axis["top"].set_visible(False)
282-
283279
ax2.axis["top"].set_visible(True)
280+
ax2.axis["top"].toggle(all=True)
281+
ax2.axis["top"].line.set_visible(False)
284282
ax2.axis["left", "right", "bottom"].set_visible(False)
285283

286284
return ax2
287285

288286
def _remove_twiny(self, ax):
289287
self.parasites.remove(ax)
290-
self.axis["top"].set_visible(True)
291-
self.axis["top"].toggle(ticklabels=False, label=False)
292288

293289
def twin(self, aux_trans=None, axes_class=None):
294290
"""
@@ -313,15 +309,13 @@ def twin(self, aux_trans=None, axes_class=None):
313309
self.parasites.append(ax2)
314310
ax2._remove_method = self.parasites.remove
315311

316-
self.axis["top", "right"].set_visible(False)
317-
318312
ax2.axis["top", "right"].set_visible(True)
313+
ax2.axis["top", "right"].toggle(all=True)
314+
ax2.axis["top", "right"].line.set_visible(False)
319315
ax2.axis["left", "bottom"].set_visible(False)
320316

321317
def _remove_method(h):
322318
self.parasites.remove(h)
323-
self.axis["top", "right"].set_visible(True)
324-
self.axis["top", "right"].toggle(ticklabels=False, label=False)
325319
ax2._remove_method = _remove_method
326320

327321
return ax2

0 commit comments

Comments
 (0)