Skip to content

Commit 61d4f69

Browse files
tacaswellmeeseeksmachine
authored andcommitted
Backport PR matplotlib#22254: Disable QuadMesh cursor data by default
1 parent 8f40942 commit 61d4f69

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
QuadMesh cursor data disabled by default
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Showing the cursor data of a `.QuadMesh` is now disabled by default, as it has
4+
significant performance issues with large meshes. To manually enable this
5+
use :meth:`.QuadMesh.set_show_cursor_data`.

lib/matplotlib/collections.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,7 @@ def __init__(self, *args, **kwargs):
20112011
self._shading = shading
20122012
self._bbox = transforms.Bbox.unit()
20132013
self._bbox.update_from_data_xy(self._coordinates.reshape(-1, 2))
2014+
self._show_cursor_data = False
20142015
# super init delayed after own init because array kwarg requires
20152016
# self._coordinates and self._shading
20162017
super().__init__(**kwargs)
@@ -2207,7 +2208,23 @@ def draw(self, renderer):
22072208
renderer.close_group(self.__class__.__name__)
22082209
self.stale = False
22092210

2211+
def set_show_cursor_data(self, show_cursor_data):
2212+
"""
2213+
Set whether cursor data should be shown.
2214+
2215+
Notes
2216+
-----
2217+
This is set to `False` by default for new quad meshes. Showing cursor
2218+
data can have significant performance impacts for large meshes.
2219+
"""
2220+
self._show_cursor_data = show_cursor_data
2221+
2222+
def get_show_cursor_data(self):
2223+
return self._show_cursor_data
2224+
22102225
def get_cursor_data(self, event):
2226+
if not self._show_cursor_data:
2227+
return
22112228
contained, info = self.contains(event)
22122229
if len(info["ind"]) == 1:
22132230
ind, = info["ind"]

lib/matplotlib/tests/test_collections.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,20 @@ def test_quadmesh_cursor_data():
10321032
fig, ax = plt.subplots()
10331033
*_, qm = ax.hist2d(
10341034
np.arange(11)**2, 100 + np.arange(11)**2) # width-10 bins
1035+
10351036
x, y = ax.transData.transform([1, 101])
10361037
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
1038+
1039+
assert qm.get_show_cursor_data() is False
1040+
assert qm.get_cursor_data(event) is None
1041+
1042+
qm.set_show_cursor_data(True)
10371043
assert qm.get_cursor_data(event) == 4 # (0**2, 1**2, 2**2, 3**2)
1038-
for out_xydata in []:
1039-
x, y = ax.transData.transform([-1, 101])
1040-
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
1041-
assert qm.get_cursor_data(event) is None
1044+
1045+
# Outside the quadmesh bounds
1046+
x, y = ax.transData.transform([-1, 101])
1047+
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
1048+
assert qm.get_cursor_data(event) is None
10421049

10431050

10441051
def test_get_segments():

0 commit comments

Comments
 (0)