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

Skip to content

Commit 7c7e251

Browse files
authored
Fix: Prevent Cursor blitting from erasing overlapping axes
* Fix: Prevent Cursor blitting from erasing overlapping axes * Fix styling: remove trailing whitespace and shorten comment * MAINT: explicitly mark Cursor blitting on overlapping axes as unsupported * style: fix ruff line length limit in widgets.py * test: add coverage for cursor overlapping axes warning * chore: trigger CI to clear Windows timeout flake
1 parent 2443c6d commit 7c7e251

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/matplotlib/tests/test_widgets.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,3 +1817,19 @@ def test_parent_axes_removal():
18171817
evt = DrawEvent('draw_event', fig.canvas, renderer)
18181818
radio._clear(evt)
18191819
checks._clear(evt)
1820+
1821+
1822+
def test_cursor_overlapping_axes_blitting_warning():
1823+
"""Test that a warning is raised and useblit is disabled for overlapping axes."""
1824+
fig = plt.figure()
1825+
ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.8])
1826+
ax2 = fig.add_axes([0.2, 0.2, 0.6, 0.6]) # Explicitly overlaps ax1
1827+
1828+
match_text = (
1829+
"Cursor blitting is currently not supported on "
1830+
"overlapping axes"
1831+
)
1832+
with pytest.warns(UserWarning, match=match_text):
1833+
cursor = widgets.Cursor(ax1, useblit=True)
1834+
1835+
assert cursor.useblit is False

lib/matplotlib/widgets.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,16 @@ def __init__(self, ax, *, horizOn=True, vertOn=True, useblit=False,
20842084
self.vertOn = vertOn
20852085
self.useblit = useblit and self.canvas.supports_blit # TODO: make dynamic
20862086

2087+
if self.useblit:
2088+
for ax_ in ax.get_figure(root=True).get_axes():
2089+
if ax_ is not ax and ax.bbox.overlaps(ax_.bbox):
2090+
_api.warn_external(
2091+
"Cursor blitting is currently not supported on "
2092+
"overlapping axes; falling back to useblit=False."
2093+
)
2094+
self.useblit = False
2095+
break
2096+
20872097
if self.useblit:
20882098
lineprops['animated'] = True
20892099
self.lineh = ax.axhline(ax.get_ybound()[0], visible=False, **lineprops)

0 commit comments

Comments
 (0)