FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Break links between twinned axes when removing by dstansby · Pull Request #21076 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions lib/matplotlib/figure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,15 @@ def _break_share_link(ax, grouper):
self.stale = True
self._localaxes.remove(ax)

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

# Break link between any twinned axes
_break_share_link(ax, ax._twinned_axes)

# Note: in the docstring below, the newlines in the examples after the
# calls to legend() allow replacing it with figlegend() to generate the
# docstring of pyplot.figlegend.
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4663,6 +4663,21 @@ def test_spectrum():
ax.set(xlabel="", ylabel="")


@check_figures_equal(extensions=['png'])
def test_twin_remove(fig_test, fig_ref):
ax_test = fig_test.add_subplot()
ax_twinx = ax_test.twinx()
ax_twiny = ax_test.twiny()
ax_twinx.remove()
ax_twiny.remove()

ax_ref = fig_ref.add_subplot()
# Ideally we also undo tick changes when calling ``remove()``, but for now
# manually set the ticks of the reference image to match the test image
ax_ref.xaxis.tick_bottom()
ax_ref.yaxis.tick_left()


@image_comparison(['twin_spines.png'], remove_text=True)
def test_twin_spines():

Expand Down

Back | FazBrowse Home | New Git URL