8000 Break links between twinned axes when removing · matplotlib/matplotlib@63ce34d · GitHub
[go: up one dir, main page]

Skip to content

Commit 63ce34d

Browse files
committed
Break links between twinned axes when removing
1 parent e34642d commit 63ce34d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,11 +928,15 @@ def _break_share_link(ax, grouper):
928928
self.stale = True
929929
self._localaxes.remove(ax)
930930

931+
# Break link between any shared axes
931932
for name in ax._axis_names:
932933
last_ax = _break_share_link(ax, ax._shared_axes[name])
933934
if last_ax is not None:
934935
_reset_locators_and_formatters(getattr(last_ax, f"{name}axis"))
935936

937+
# Break link between any twinned axes
938+
_break_share_link(ax, ax._twinned_axes)
939+
936940
# Note: in the docstring below, the newlines in the examples after the
937941
# calls to legend() allow replacing it with figlegend() to generate the
938942
# docstring of pyplot.figlegend.

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,6 +4663,21 @@ def test_spectrum():
46634663
ax.set(xlabel="", ylabel="")
46644664

46654665

4666+
@check_figures_equal(extensions=['png'])
4667+
def test_twin_remove(fig_test, fig_ref):
4668+
ax_test = fig_test.add_subplot()
4669+
ax_twinx = ax_test.twinx()
4670+
ax_twiny = ax_test.twiny()
4671+
ax_twinx.remove()
4672+
ax_twiny.remove()
4673+
4674+
ax_ref = fig_ref.add_subplot()
4675+
# Ideally we also undo tick changes when calling ``remove()``, but for now
4676+
# manually set the ticks of the reference image to match the test image
4677+
ax_ref.xaxis.tick_bottom()
4678+
ax_ref.yaxis.tick_left()
4679+
4680+
46664681
@image_comparison(['twin_spines.png'], remove_text=True)
46674682
def test_twin_spines():
46684683

0 commit comments

Comments
 (0)
0