From 2b30478c82805deba718ca8b9788760413a876a9 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 23 Mar 2022 22:37:41 +0100 Subject: [PATCH 1/3] FIX: completely remove QuadMesh cursor data --- .../next_api_changes/behavior/22254-DS.rst | 5 ---- .../next_api_changes/behavior/22691-JMK.rst | 4 +++ lib/matplotlib/collections.py | 25 ------------------- lib/matplotlib/tests/test_collections.py | 21 ---------------- 4 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 doc/api/next_api_changes/behavior/22254-DS.rst create mode 100644 doc/api/next_api_changes/behavior/22691-JMK.rst diff --git a/doc/api/next_api_changes/behavior/22254-DS.rst b/doc/api/next_api_changes/behavior/22254-DS.rst deleted file mode 100644 index 83e53ae60477..000000000000 --- a/doc/api/next_api_changes/behavior/22254-DS.rst +++ /dev/null @@ -1,5 +0,0 @@ -QuadMesh cursor data disabled by default -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Showing the cursor data of a `.QuadMesh` is now disabled by default, as it has -significant performance issues with large meshes. To manually enable this -use :meth:`.QuadMesh.set_show_cursor_data`. diff --git a/doc/api/next_api_changes/behavior/22691-JMK.rst b/doc/api/next_api_changes/behavior/22691-JMK.rst new file mode 100644 index 000000000000..548f70e3c2a0 --- /dev/null +++ b/doc/api/next_api_changes/behavior/22691-JMK.rst @@ -0,0 +1,4 @@ +QuadMesh cursor data removed +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`.QuadMesh.get_cursor_data`, introduced in 3.5.1 is unreasonably slow for +large meshes, so this method has been removed. diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index e48fe55f51c3..a1e8ebcd383d 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -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) @@ -2197,27 +2196,3 @@ def draw(self, renderer): gc.restore() 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"] - return self.get_array()[ind] - else: - return None diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index acca60fd01c1..2dffdf9cf893 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -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 @@ -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]) From e964496482fb611cf0b19212a8e487fb060517f1 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 24 Mar 2022 09:24:02 +0100 Subject: [PATCH 2/3] FIX: re-add get_cursor_data now that mouseover is set to False by default --- lib/matplotlib/collections.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index a1e8ebcd383d..0644ff7027c3 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -2196,3 +2196,11 @@ def draw(self, renderer): gc.restore() renderer.close_group(self.__class__.__name__) self.stale = False + + def get_cursor_data(self, event): + contained, info = self.contains(event) + if len(info["ind"]) == 1: + ind, = info["ind"] + return self.get_array()[ind] + else: + return None From 8971f1d8c2678c4a079238e96e1ce92f379819e8 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 24 Mar 2022 11:10:21 +0100 Subject: [PATCH 3/3] DOC: adjust behavior message --- doc/api/next_api_changes/behavior/22691-JMK.rst | 10 ++++++---- lib/matplotlib/collections.py | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/api/next_api_changes/behavior/22691-JMK.rst b/doc/api/next_api_changes/behavior/22691-JMK.rst index 548f70e3c2a0..24519d97e371 100644 --- a/doc/api/next_api_changes/behavior/22691-JMK.rst +++ b/doc/api/next_api_changes/behavior/22691-JMK.rst @@ -1,4 +1,6 @@ -QuadMesh cursor data removed -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -`.QuadMesh.get_cursor_data`, introduced in 3.5.1 is unreasonably slow for -large meshes, so this method has been removed. +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*. \ No newline at end of file diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 0644ff7027c3..1fe17f3e982e 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -2198,9 +2198,9 @@ def draw(self, renderer): self.stale = False def get_cursor_data(self, event): - contained, info = self.contains(event) - if len(info["ind"]) == 1: - ind, = info["ind"] - return self.get_array()[ind] - else: - return None + contained, info = self.contains(event) + if len(info["ind"]) == 1: + ind, = info["ind"] + return self.get_array()[ind] + else: + return None