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

Skip to content

FIX: remove toggle on QuadMesh cursor data #22691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2022
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
5 changes: 0 additions & 5 deletions doc/api/next_api_changes/behavior/22254-DS.rst

This file was deleted.

6 changes: 6 additions & 0 deletions doc/api/next_api_changes/behavior/22691-JMK.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
QuadMesh mouseover defaults to False
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

New in 3.5, `.QuadMesh.get_cursor_data` allows display of data values
under the cursor. However, this can be very slow for large meshes, so
by `.QuadMesh.set_mouseover` defaults to *False*.
17 changes: 0 additions & 17 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,6 @@ def __init__(self, *args, **kwargs):
self._shading = shading
self._bbox = transforms.Bbox.unit()
self._bbox.update_from_data_xy(self._coordinates.reshape(-1, 2))
self._show_cursor_data = False
# super init delayed after own init because array kwarg requires
# self._coordinates and self._shading
super().__init__(**kwargs)
Expand Down Expand Up @@ -2198,23 +2197,7 @@ def draw(self, renderer):
renderer.close_group(self.__class__.__name__)
self.stale = False

def set_show_cursor_data(self, show_cursor_data):
"""
Set whether cursor data should be shown.

Notes
-----
This is set to `False` by default for new quad meshes. Showing cursor
data can have significant performance impacts for large meshes.
"""
self._show_cursor_data = show_cursor_data

def get_show_cursor_data(self):
return self._show_cursor_data

def get_cursor_data(self, event):
if not self._show_cursor_data:
return
contained, info = self.contains(event)
if len(info["ind"]) == 1:
ind, = info["ind"]
Expand Down
21 changes: 0 additions & 21 deletions lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.backend_bases import MouseEvent
import matplotlib.collections as mcollections
import matplotlib.colors as mcolors
import matplotlib.transforms as mtransforms
Expand Down Expand Up @@ -1039,26 +1038,6 @@ def test_array_wrong_dimensions():
pc.update_scalarmappable()


def test_quadmesh_cursor_data():
fig, ax = plt.subplots()
*_, qm = ax.hist2d(
np.arange(11)**2, 100 + np.arange(11)**2) # width-10 bins

x, y = ax.transData.transform([1, 101])
event = MouseEvent('motion_notify_event', fig.canvas, x, y)

assert qm.get_show_cursor_data() is False
assert qm.get_cursor_data(event) is None

qm.set_show_cursor_data(True)
assert qm.get_cursor_data(event) == 4 # (0**2, 1**2, 2**2, 3**2)

# Outside the quadmesh bounds
x, y = ax.transData.transform([-1, 101])
event = MouseEvent('motion_notify_event', fig.canvas, x, y)
assert qm.get_cursor_data(event) is None


def test_get_segments():
segments = np.tile(np.linspace(0, 1, 256), (2, 1)).T
lc = LineCollection([segments])
Expand Down