aind_ephys_utils.plots.psth module

PSTH plotting helpers.

aind_ephys_utils.plots.psth.psth(data: DataArray, *, group_by: str | Sequence[str] | None = None, dim: str = 'trial', method: str = 'mean', compute: bool = True, ax: Axes | None = None, events: Sequence[float] | ndarray | DataArray | None = None, intervals: Sequence[Tuple[float, float]] | ndarray | DataArray | None = None, event_labels: Sequence[str] | Dict[float, str] | None = None, interval_labels: Sequence[str] | Dict[Tuple[float, float], str] | None = None, event_style: dict | None = None, interval_style: dict | None = None, color: str | None = None, alpha: float = 1.0, linewidth: float = 1.5, label: str | None = None, hide_axes: bool = False, x_scale: float | None = None, y_scale: float | None = None, x_scale_text: str | None = None, y_scale_text: str | None = None) tuple[DataArray, Axes | None]

Plot a PSTH from a binned/continuous DataArray.

Parameters:
  • data – Input DataArray. Selection of units/trials should be done upstream. If compute=True and dim is present, ops.psth is used to reduce.

  • group_by – Optional trial coord(s) to split and plot conditions.

  • dim – Trial dimension to reduce across when compute=True.

  • method – Reduction method passed to ops.psth.

  • compute – If True, compute the PSTH from data using ops.psth.

  • ax – Matplotlib Axes to draw on; created if None.

  • events – Optional event times to overlay as vertical lines.

  • intervals – Optional intervals to overlay as shaded regions.

  • event_labels – Optional labels for events (sequence aligned with events or mapping).

  • interval_labels – Optional labels for intervals (sequence aligned with intervals or mapping).

  • event_style – Optional styling dict passed to ax.axvline.

  • interval_style – Optional styling dict passed to ax.axvspan.

  • color – Plot styling options.

  • alpha – Plot styling options.

  • linewidth – Plot styling options.

  • label – Plot styling options.

  • hide_axes – If True, hide axes and draw scale bars.

  • x_scale – Optional length of x-axis scale bar in data units.

  • y_scale – Optional length of y-axis scale bar in data units.

  • x_scale_text – Optional label text for the x-axis scale bar.

  • y_scale_text – Optional label text for the y-axis scale bar.

Returns:

psth_da is the reduced DataArray; ax is the matplotlib Axes (or None).

Return type:

(psth_da, ax)