From 2d0cc7da4226ed5634c8ce6197b52df886afdf76 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 28 Jul 2015 03:19:19 -0400 Subject: [PATCH 1/2] PRF: only do expensive things once Looking up MachAr was taking about 10ms which is way to slow to be inside of the mouse motion event loop. We are using it to get a constant so we can look it up and compute the constant once at the top. --- lib/matplotlib/transforms.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 75fda8c1d230..0df6ea4c4b12 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -50,7 +50,8 @@ from .path import Path DEBUG = False - +# we need this later, but this is very expensive to set up +MINFLOAT = np.MachAr(float).xmin MaskedArray = ma.MaskedArray @@ -2738,7 +2739,7 @@ def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True): swapped = True maxabsvalue = max(abs(vmin), abs(vmax)) - if maxabsvalue < (1e6 / tiny) * np.MachAr(float).xmin: + if maxabsvalue < (1e6 / tiny) * MINFLOAT: vmin = -expander vmax = expander From a4557c29bbadb3bdcb893f344c2a279b9be510a8 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 28 Jul 2015 17:26:57 -0400 Subject: [PATCH 2/2] PRF: minor performance tweaks --- lib/matplotlib/backend_bases.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index c82e0f34850c..d0b59e5b7524 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2813,15 +2813,14 @@ def mouse_move(self, event): pass else: artists = event.inaxes.hitlist(event) - if event.inaxes.patch in artists: - artists.remove(event.inaxes.patch) if artists: - artists.sort(key=lambda x: x.zorder) - a = artists[-1] - data = a.get_cursor_data(event) - if data is not None: - s += ' [%s]' % a.format_cursor_data(data) + a = max(enumerate(artists), key=lambda x: x[1].zorder)[1] + if a is not event.inaxes.patch: + data = a.get_cursor_data(event) + if data is not None: + s += ' [%s]' % a.format_cursor_data(data) + if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) else: