From 27c93f276792aa30652aceb574af6c153d253e1d Mon Sep 17 00:00:00 2001 From: Andrew Mark Date: Mon, 11 Apr 2016 15:43:05 +0200 Subject: [PATCH 1/2] Update annotate docstring --- trackpy/plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trackpy/plots.py b/trackpy/plots.py index 5a262e6e..98d0b646 100644 --- a/trackpy/plots.py +++ b/trackpy/plots.py @@ -395,7 +395,7 @@ def plot_traj3d(*args, **kwargs): def annotate(centroids, image, circle_size=None, color=None, invert=False, ax=None, split_category=None, split_thresh=None, imshow_style={}, plot_style={}): - """Mark identified features with white circles. + """Mark identified features with circles. Parameters ---------- From 1731711505811a3d1525457649d5c9db845ed2f2 Mon Sep 17 00:00:00 2001 From: Andrew Mark Date: Tue, 12 Apr 2016 11:11:09 +0200 Subject: [PATCH 2/2] Added particle labelling to plot.annotate --- trackpy/plots.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/trackpy/plots.py b/trackpy/plots.py index 98d0b646..54a3422e 100644 --- a/trackpy/plots.py +++ b/trackpy/plots.py @@ -392,9 +392,9 @@ def plot_traj3d(*args, **kwargs): ptraj3d = plot_traj3d @make_axes -def annotate(centroids, image, circle_size=None, color=None, +def annotate(centroids, image, circle_size=None, label=False, color=None, invert=False, ax=None, split_category=None, split_thresh=None, - imshow_style={}, plot_style={}): + imshow_style={}, plot_style={}, label_style={}): """Mark identified features with circles. Parameters @@ -404,6 +404,8 @@ def annotate(centroids, image, circle_size=None, color=None, circle_size : Deprecated. This will be removed in a future version of trackpy. Use `plot_style={'markersize': ...}` instead. + label : boolean, optional + Set to True to write particle ID or row numbers next to markers. color : single matplotlib color or a list of multiple colors default None invert : If you give a filepath as the image, specify whether to invert @@ -419,6 +421,8 @@ def annotate(centroids, image, circle_size=None, color=None, the `Axes.imshow(...)` command the displays the image plot_style : dictionary of keyword arguments passed through to the `Axes.plot(...)` command that marks the features + label_style : dictionary of keyword arguments passed through to + the `Axes.annotate(...)` command that labels the features Returns ------- @@ -504,6 +508,14 @@ def pairwise(iterable): _plot_style.update(markeredgecolor=color[-1]) ax.plot(centroids['x'][high], centroids['y'][high], **_plot_style) + + if label: + if 'particle' in centroids.columns: + for (i, row) in centroids.iterrows(): + ax.annotate(str(row.particle), (row.x, row.y), **label_style) + else: + for (i, row) in centroids.iterrows(): + ax.annotate(str(i), (row.x, row.y), **label_style) return ax