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

Skip to content

Commit 63a65c5

Browse files
committed
Disalbe showing cursor data on a QuadMesh by default
1 parent 76012ae commit 63a65c5

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Showing the cursor data of a `.QuadMesh` is now disabled by default, as it has
2+
significant performance issues with large meshes. To manually enable this
3+
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
@@ -2000,6 +2000,7 @@ def __init__(self, *args, **kwargs):
20002000
self._shading = shading
20012001
self._bbox = transforms.Bbox.unit()
20022002
self._bbox.update_from_data_xy(self._coordinates.reshape(-1, 2))
2003+
self._show_cursor_data = False
20032004
# super init delayed after own init because array kwarg requires
20042005
# self._coordinates and self._shading
20052006
super().__init__(**kwargs)
@@ -2197,7 +2198,23 @@ def draw(self, renderer):
21972198
renderer.close_group(self.__class__.__name__)
21982199
self.stale = False
21992200

2201+
def set_show_cursor_data(self, show_cursor_data):
2202+
"""
2203+
Set whether cursor data should be shown.
2204+
2205+
Notes
2206+
-----
2207+
This is set to `False` by default for new quad meshes. Showing cursor
2208+
data can have significant performance impacts for large meshes.
2209+
"""
2210+
self._show_cursor_data = show_cursor_data
2211+
2212+
def get_show_cursor_data(self):
2213+
return self._show_cursor_data
2214+
22002215
def get_cursor_data(self, event):
2216+
if not self._show_cursor_data:
2217+
return
22012218
contained, info = self.contains(event)
22022219
if len(info["ind"]) == 1:
22032220
ind, = info["ind"]

lib/matplotlib/tests/test_collections.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,13 +1027,20 @@ def test_quadmesh_cursor_data():
10271027
fig, ax = plt.subplots()
10281028
*_, qm = ax.hist2d(
10291029
np.arange(11)**2, 100 + np.arange(11)**2) # width-10 bins
1030+
10301031
x, y = ax.transData.transform([1, 101])
10311032
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
1033+
1034+
assert qm.get_show_cursor_data() is False
1035+
assert qm.get_cursor_data(event) is None
1036+
1037+
qm.set_show_cursor_data(True)
10321038
assert qm.get_cursor_data(event) == 4 # (0**2, 1**2, 2**2, 3**2)
1033-
for out_xydata in []:
1034-
x, y = ax.transData.transform([-1, 101])
1035-
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
1036-
assert qm.get_cursor_data(event) is None
1039+
1040+
# Outside the quadmesh bounds
1041+
x, y = ax.transData.transform([-1, 101])
1042+
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
1043+
assert qm.get_cursor_data(event) is None
10371044

10381045

10391046
def test_get_segments():

0 commit comments

Comments
 (0)