8000 Merge pull request #21076 from dstansby/twin-remove · matplotlib/matplotlib@bb2bf7c · GitHub
[go: up one dir, main page]

Skip to content

Commit bb2bf7c

Browse files
authored
Merge pull request #21076 from dstansby/twin-remove
FIX: Break links between twinned axes when removing
2 parents 20a2bce + 63ce34d commit bb2bf7c

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
@@ -4664,6 +4664,21 @@ def test_spectrum():
46644664
ax.set(xlabel="", ylabel="")
46654665

46664666

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

0 commit comments

Comments
 (0)
0