From fed35fa927f2aebb25512234b0b3a33e7cafc090 Mon Sep 17 00:00:00 2001 From: Alessandro Impellizzeri Date: Tue, 18 Feb 2014 15:23:02 +0100 Subject: [PATCH 1/9] Update pick_info.py line_props is now line_props_interpolated as it interpolates values between original values. The simple way to get original plot values is now line_props --- mpldatacursor/pick_info.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mpldatacursor/pick_info.py b/mpldatacursor/pick_info.py index aa0dbab..6691916 100644 --- a/mpldatacursor/pick_info.py +++ b/mpldatacursor/pick_info.py @@ -71,7 +71,7 @@ def image_props(event): z = ', '.join('{:0.3g}'.format(item) for item in z) return dict(z=z, i=i, j=j) -def line_props(event): +def line_props_interpolated(event): """ Get information for a pick event on a Line2D artist (as created with ``plot``.) @@ -110,6 +110,31 @@ def line_props(event): x, y = np.array([x0, y0]) + dist_along * vec1 return dict(x=x, y=y) + +def line_props(event): + """ + Get information for a pick event on a Line2D artist (as created with + ``plot``.) + + This will yield x and y values on the nearest pick position of the mouse + + + Parameters + ----------- + event : PickEvent + The pick event to process + + Returns + -------- + props : dict + A dict with keys: x & y + """ + xclick, yclick = event.mouseevent.xdata, event.mouseevent.ydata + i = event.ind[0] + xorig, yorig = event.artist.get_xydata().T + + + return dict(x=xorig[i], y=yorig[i]) def collection_props(event): """ From 6bc123cb072ce1aea584e4f03c4aa9eb897a2e4b Mon Sep 17 00:00:00 2001 From: Alessandro Impellizzeri Date: Tue, 18 Feb 2014 15:34:44 +0100 Subject: [PATCH 2/9] Update datacursor.py added a parameter to select if the pick info in 2D plots is interpolated or not. --- mpldatacursor/datacursor.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mpldatacursor/datacursor.py b/mpldatacursor/datacursor.py index 5c75dc9..aa1d614 100644 --- a/mpldatacursor/datacursor.py +++ b/mpldatacursor/datacursor.py @@ -41,7 +41,7 @@ class DataCursor(object): arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0')) def __init__(self, artists, tolerance=5, formatter=None, point_labels=None, - display='one-per-axes', draggable=False, **kwargs): + display='one-per-axes', draggable=False,interpolate_pickpos=True, **kwargs): """Create the data cursor and connect it to the relevant figure. Parameters @@ -66,9 +66,20 @@ def __init__(self, artists, tolerance=5, formatter=None, point_labels=None, draggable : boolean, optional Controls whether or not the annotation box will be interactively draggable to a new location after being displayed. Default: False. + interpolate_pickpos: boolean defines what kind of line pick function to use. + If set to true the interpolated version will be used. + If false the nearest point to the left will be picked. **kwargs : additional keyword arguments, optional Additional keyword arguments are passed on to annotate. """ + #define which kind of line_props to use. + #line_props <- easy version + #line_props_interpolated <- interpolated version + if (interpolate_pickpos): + self.line_props = pick_info.line_props_interpolated + else: + self.line_props = pick_info.line_props + def filter_artists(artists): """Replace ContourSets with their constituent artists.""" output = [] @@ -150,7 +161,7 @@ def default_func(event): AxesImage : [pick_info.image_props], PathCollection : [pick_info.scatter_props, self._contour_info, pick_info.collection_props], - Line2D : [pick_info.line_props], + Line2D : [self.line_props], LineCollection : [pick_info.collection_props, self._contour_info], PatchCollection : [pick_info.collection_props, From dbbcf4f0e97d73b0fd036177c421158c0870f19c Mon Sep 17 00:00:00 2001 From: Alessandro Impellizzeri Date: Tue, 18 Feb 2014 15:48:02 +0100 Subject: [PATCH 3/9] Update __init__.py python 3 support --- mpldatacursor/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpldatacursor/__init__.py b/mpldatacursor/__init__.py index d1a9401..65051e2 100644 --- a/mpldatacursor/__init__.py +++ b/mpldatacursor/__init__.py @@ -21,6 +21,6 @@ """ __version__ = '0.4-dev' -from convenience import datacursor -from datacursor import DataCursor, HighlightingDataCursor +from .convenience import datacursor +from .datacursor import DataCursor, HighlightingDataCursor __all__ = ['datacursor', 'DataCursor', 'HighlightingDataCursor'] From 1828568fda450ef815eebecb997f30514bab915c Mon Sep 17 00:00:00 2001 From: Alessandro Impellizzeri Date: Tue, 18 Feb 2014 15:48:25 +0100 Subject: [PATCH 4/9] Update datacursor.py python 3 support --- mpldatacursor/datacursor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpldatacursor/datacursor.py b/mpldatacursor/datacursor.py index aa1d614..312f051 100644 --- a/mpldatacursor/datacursor.py +++ b/mpldatacursor/datacursor.py @@ -29,7 +29,7 @@ from matplotlib.collections import PatchCollection, PolyCollection, QuadMesh from matplotlib.lines import Line2D -import pick_info +from . import pick_info class DataCursor(object): """A simple data cursor widget that displays the x,y location of a From 85bd8f37157ec4469f2fd940389715097e01e503 Mon Sep 17 00:00:00 2001 From: Alessandro Impellizzeri Date: Tue, 18 Feb 2014 15:50:07 +0100 Subject: [PATCH 5/9] Update convenience.py python 3 support --- mpldatacursor/convenience.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpldatacursor/convenience.py b/mpldatacursor/convenience.py index d32b8eb..9bd6a2f 100644 --- a/mpldatacursor/convenience.py +++ b/mpldatacursor/convenience.py @@ -22,7 +22,7 @@ from matplotlib import _pylab_helpers as pylab_helpers from matplotlib import cbook -from datacursor import DataCursor +from .datacursor import DataCursor def datacursor(artists=None, axes=None, **kwargs): """ From 3ee1c920d094e44b94b7ef3b37b1eb7bfd3cc730 Mon Sep 17 00:00:00 2001 From: Alessandro Impellizzeri Date: Mon, 21 Jul 2014 12:30:23 +0200 Subject: [PATCH 6/9] Update pick_info.py Get nearest click point with line_props --- mpldatacursor/pick_info.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mpldatacursor/pick_info.py b/mpldatacursor/pick_info.py index 6691916..ae13e1e 100644 --- a/mpldatacursor/pick_info.py +++ b/mpldatacursor/pick_info.py @@ -130,10 +130,18 @@ def line_props(event): A dict with keys: x & y """ xclick, yclick = event.mouseevent.xdata, event.mouseevent.ydata - i = event.ind[0] + #i = event.ind[0] + #Search the nearest point xorig, yorig = event.artist.get_xydata().T - - + d = ((xclick-xorig[0])**2 + (yclick-yorig[0])**2)**0.5 + i=0 + import pdb + for itmp,(xo,yo) in enumerate(zip(xorig[1:],yorig[1:])): + dtmp = ((xclick-xo)**2 + (yclick-yo)**2)**0.5 + if dtmp Date: Mon, 21 Jul 2014 12:31:25 +0200 Subject: [PATCH 7/9] Update pick_info.py --- mpldatacursor/pick_info.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mpldatacursor/pick_info.py b/mpldatacursor/pick_info.py index ae13e1e..2a5a90d 100644 --- a/mpldatacursor/pick_info.py +++ b/mpldatacursor/pick_info.py @@ -141,7 +141,6 @@ def line_props(event): if dtmp Date: Mon, 21 Jul 2014 12:32:02 +0200 Subject: [PATCH 8/9] Update pick_info.py --- mpldatacursor/pick_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpldatacursor/pick_info.py b/mpldatacursor/pick_info.py index 2a5a90d..b7612b0 100644 --- a/mpldatacursor/pick_info.py +++ b/mpldatacursor/pick_info.py @@ -135,7 +135,7 @@ def line_props(event): xorig, yorig = event.artist.get_xydata().T d = ((xclick-xorig[0])**2 + (yclick-yorig[0])**2)**0.5 i=0 - import pdb + for itmp,(xo,yo) in enumerate(zip(xorig[1:],yorig[1:])): dtmp = ((xclick-xo)**2 + (yclick-yo)**2)**0.5 if dtmp Date: Mon, 21 Jul 2014 12:37:58 +0200 Subject: [PATCH 9/9] Update datacursor.py interpolate_pickpos standard is false not true --- mpldatacursor/datacursor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpldatacursor/datacursor.py b/mpldatacursor/datacursor.py index 312f051..baebbc0 100644 --- a/mpldatacursor/datacursor.py +++ b/mpldatacursor/datacursor.py @@ -41,7 +41,7 @@ class DataCursor(object): arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0')) def __init__(self, artists, tolerance=5, formatter=None, point_labels=None, - display='one-per-axes', draggable=False,interpolate_pickpos=True, **kwargs): + display='one-per-axes', draggable=False,interpolate_pickpos=False, **kwargs): """Create the data cursor and connect it to the relevant figure. Parameters