Skip to content

Commit

Permalink
Change order of arguments for show_positions, fix arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sitic committed Feb 24, 2024
1 parent 0cd803d commit 6256a25
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
"positions = [(127, 147), (130, 209), (202, 136)]\n",
"\n",
"fig, axs = plt.subplots(1,2, figsize=(11,4))\n",
"om.trace.show_positions(video[0], positions, ax=axs[0])\n",
"om.trace.show_positions(positions, video[0], ax=axs[0])\n",
"traces = om.trace.extract_traces(video, positions, size=5, ax=axs[1], show=True, fps=500)\n",
"plt.show()"
]
Expand Down Expand Up @@ -292,7 +292,7 @@
"source": [
"fig, axs = plt.subplots(1, 2, figsize=(10,5))\n",
"\n",
"om.trace.show_positions(video[0], positions, ax=axs[0])\n",
"om.trace.show_positions(positions, video[0], ax=axs[0])\n",
"\n",
"x_axis_ms = (np.arange(video.shape[0]) / 500.0) * 1000\n",
"traces = om.extract_traces(video[:300],\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/ratiometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"metadata": {},
"outputs": [],
"source": [
"om.show_positions(video_green[0], positions)"
"om.show_positions(positions, video_green[0])"
]
},
{
Expand Down
32 changes: 23 additions & 9 deletions optimap/trace/_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import matplotlib.pyplot as plt
import numpy as np

Expand Down Expand Up @@ -114,19 +116,21 @@ def rect_mask(video, x, y):
return traces


def show_positions(image, positions, size=None, cmap="gray", vmin=None, vmax=None, ax=None, **kwargs):
def show_positions(positions, image=None, size=None, color=None, cmap="gray", vmin=None, vmax=None, ax=None, **kwargs):
"""Overlay positions on an image.
Parameters
----------
image : 2D array
Image to overlay positions on
positions : list of tuples
List of positions to overlay
image : 2D array
Image to overlay positions on, optional
size : float or array-like, shape (n, ), optional
Size of the points, see `s` parameter in :py:func:`matplotlib.pyplot.scatter` for more information
color : str or list of str, optional
Color of the points, by default None
cmap : str, optional
Colormap to use, by default 'gray'
Colormap to use for image, by default 'gray'
vmin : float, optional
Minimum value for the colormap, by default None
vmax : float, optional
Expand All @@ -145,11 +149,21 @@ def show_positions(image, positions, size=None, cmap="gray", vmin=None, vmax=Non
show = True
else:
show = False

ax.imshow(image, cmap=cmap, vmin=vmin, vmax=vmax, interpolation="none")
ax.axis("off")
for pos in positions:
ax.scatter(pos[0], pos[1], s=size, **kwargs)

if isinstance(image, np.ndarray) and image.ndim == 2 and image.shape[1] == 2:
image, positions = positions, image
warnings.warn("The order of arguments for optimap.show_positions() has changed.", DeprecationWarning)

if image is not None:
ax.imshow(image, cmap=cmap, vmin=vmin, vmax=vmax, interpolation="none")
ax.axis("off")

if isinstance(color, str) or color is None:
color = [color, ] * len(positions)
if isinstance(size, (int, float)) or size is None:
size = [size, ] * len(positions)
for pos, s, c in zip(positions, size, color):
ax.scatter(pos[0], pos[1], s=s, c=c, **kwargs)
if show:
plt.show()
return ax
Expand Down

0 comments on commit 6256a25

Please sign in to comment.