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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,3 +1817,19 @@ def test_parent_axes_removal():
evt = DrawEvent('draw_event', fig.canvas, renderer)
radio._clear(evt)
checks._clear(evt)


def test_cursor_overlapping_axes_blitting_warning():
"""Test that a warning is raised and useblit is disabled for overlapping axes."""
fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.8])
ax2 = fig.add_axes([0.2, 0.2, 0.6, 0.6]) # Explicitly overlaps ax1

match_text = (
"Cursor blitting is currently not supported on "
"overlapping axes"
)
with pytest.warns(UserWarning, match=match_text):
cursor = widgets.Cursor(ax1, useblit=True)

assert cursor.useblit is False
10 changes: 10 additions & 0 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,16 @@ def __init__(self, ax, *, horizOn=True, vertOn=True, useblit=False,
self.vertOn = vertOn
self.useblit = useblit and self.canvas.supports_blit # TODO: make dynamic

if self.useblit:
for ax_ in ax.get_figure(root=True).get_axes():
if ax_ is not ax and ax.bbox.overlaps(ax_.bbox):
_api.warn_external(
"Cursor blitting is currently not supported on "
"overlapping axes; falling back to useblit=False."
)
self.useblit = False
break

if self.useblit:
lineprops['animated'] = True
self.lineh = ax.axhline(ax.get_ybound()[0], visible=False, **lineprops)
Expand Down
Loading