Skip to content
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

Added particle labelling to plot.annotate(). #358

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions trackpy/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put new kwargs at the end of the list (think of the case where someone is using annotate(cent, img, 5, 'b') this is now silently (as in the code runs) but does something different).

invert=False, ax=None, split_category=None, split_thresh=None,
imshow_style={}, plot_style={}):
"""Mark identified features with white circles.
imshow_style={}, plot_style={}, label_style={}):
"""Mark identified features with circles.

Parameters
----------
Expand All @@ -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
Expand All @@ -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
-------
Expand Down Expand Up @@ -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


Expand Down