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

Skip to content

Commit 071e62f

Browse files
committed
Disable QuadMesh cursor data by default
1 parent 76012ae commit 071e62f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-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 `.QaudMesh` is now disabled by default, as it has
2+
significant performance issues with large meshes. To manually enable this
3+
set ``my_quad_mesh.show_cursor_data = True``.

lib/matplotlib/collections.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,12 @@ class QuadMesh(Collection):
19341934
19351935
shading : {'flat', 'gouraud'}, default: 'flat'
19361936
1937+
Attributes
1938+
----------
1939+
show_cursor_data : bool
1940+
Whether to show cursor data on an interactive plot. For large
1941+
QuadMeshes this is currently extermely show, so is disabled by default.
1942+
19371943
Notes
19381944
-----
19391945
Unlike other `.Collection`\s, the default *pickradius* of `.QuadMesh` is 0,
@@ -2000,6 +2006,7 @@ def __init__(self, *args, **kwargs):
20002006
self._shading = shading
20012007
self._bbox = transforms.Bbox.unit()
20022008
self._bbox.update_from_data_xy(self._coordinates.reshape(-1, 2))
2009+
self.show_cursor_data = False
20032010
# super init delayed after own init because array kwarg requires
20042011
# self._coordinates and self._shading
20052012
super().__init__(**kwargs)
@@ -2198,6 +2205,8 @@ def draw(self, renderer):
21982205
self.stale = False
21992206

22002207
def get_cursor_data(self, event):
2208+
if not self.show_cursor_data:
2209+
return
22012210
contained, info = self.contains(event)
22022211
if len(info["ind"]) == 1:
22032212
ind, = info["ind"]

lib/matplotlib/tests/test_collections.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,13 +1027,16 @@ 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+
assert qm.get_cursor_data(event) is None
1034+
qm.show_cursor_data = True
10321035
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
1036+
1037+
x, y = ax.transData.transform([-1, 101])
1038+
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
1039+
assert qm.get_cursor_data(event) is None
10371040

10381041

10391042
def test_get_segments():

0 commit comments

Comments
 (0)