AnimalPlotter#

class neurodent.plotting.AnimalPlotter(
war: WindowAnalysisResult,
save_fig: bool = False,
save_path: Path | None = None,
)[source]#

Bases: object

Class for plotting results from an AnimalOrganizer/WindowAnalysisResult.

Parameters:
  • war (WindowAnalysisResult) – The analysis results to plot.

  • save_fig (bool, optional) – Whether to save figures to disk. Defaults to False.

  • save_path (Path, optional) – Directory where figures will be saved. Defaults to None.

Variables:
  • window_result (WindowAnalysisResult) – The analysis results being plotted.

  • genotype (str) – Genotype of the animal.

  • channel_names (list[str]) – List of channel names.

  • n_channels (int) – Number of channels.

  • channel_abbrevs (list[str]) – Abbreviated channel names for plotting.

  • save_fig (bool) – Whether to save figures to disk.

  • save_path (Path) – Directory where figures will be saved.

__init__(
war: WindowAnalysisResult,
save_fig: bool = False,
save_path: Path | None = None,
) → None[source]#
plot_coherecorr_matrix(
groupby: str = 'animalday',
bands: list[str] | str | None = None,
figsize: tuple[float, float] | None = None,
cmap: str = 'viridis',
**kwargs,
) → None[source]#

Plot group-averaged connectivity matrices, one column per band.

Parameters:
  • groupby – Column to average over before plotting. Defaults to “animalday”.

  • bands – Band names to plot, plus “pcorr” or “zpcorr” for the correlation matrices. Defaults to every band plus “pcorr”.

  • figsize (tuple, optional) – Figure size (width, height). Defaults to None.

  • cmap (str, optional) – Colormap. Defaults to “viridis”.

plot_coherecorr_diff(
groupby: str = 'isday',
bands: list[str] | str | None = None,
figsize: tuple[float, float] | None = None,
cmap: str = 'bwr',
**kwargs,
) → None[source]#

Plot the difference in connectivity matrices between exactly two groups.

Parameters:
  • groupby – Column to split on. Must yield exactly two rows. Defaults to “isday”.

  • bands – Band names to plot, plus “pcorr” or “zpcorr” for the correlation matrices. Defaults to every band plus “pcorr”.

  • figsize (tuple, optional) – Figure size (width, height). Defaults to None.

  • cmap (str, optional) – Diverging colormap. Defaults to “bwr”.

plot_linear_temporal(
multiindex: list[str] = ['animalday', 'animal', 'genotype'],
features: list[Literal['rms', 'ampvar', 'psdtotal', 'nspike', 'logrms', 'logampvar', 'logpsdtotal', 'lognspike', 'psdslope', 'psdband', 'psdfrac', 'logpsdband', 'logpsdfrac']] | None = None,
channels: list[int] | None = None,
figsize: tuple[float, float] | None = None,
score_type: Literal['z', 'zall', 'gz', 'modz', 'center', 'none'] | None = 'z',
show_endfile: bool = False,
**kwargs,
) → None[source]#

Plot linear and band features over time, one subplot per feature.

Parameters:
  • multiindex (list[str], optional) – Index levels identifying each recording session.

  • features – Linear or band feature names to plot, see neurodent.constants.analysis.LINEAR_FEATURES and neurodent.constants.analysis.BAND_FEATURES. Defaults to the non-log linear and band features.

  • channels (list[int], optional) – Channel indices to plot. Defaults to all.

  • figsize (tuple, optional) – Figure size (width, height). Defaults to None.

  • score_type (str, optional) – Standardization applied per channel. One of “z”, “zall”, “gz”, “modz”, “center”, or “none”. Defaults to “z”.

  • show_endfile (bool, optional) – Draw vertical lines at recording file boundaries. Defaults to False.

plot_coherecorr_spectral(
multiindex: list[str] = ['animalday', 'animal', 'genotype'],
features: list[Literal['cohere', 'zcohere', 'imcoh', 'zimcoh', 'pcorr', 'zpcorr']] | None = None,
figsize: tuple[float, float] | None = None,
score_type: Literal['z', 'zall', 'gz', 'modz', 'center', 'none'] | None = 'z',
cmap: str = 'bwr',
triag: bool = True,
show_endfile: bool = False,
duration_name: str = 'duration',
endfile_name: str = 'endfile',
**kwargs,
) → None[source]#

Plot connectivity matrix features over time as per-band heatmaps.

Parameters:
  • multiindex (list[str], optional) – Index levels identifying each recording session.

  • features – Matrix feature names to plot, see neurodent.constants.analysis.MATRIX_FEATURES. Defaults to ["zcohere", "zpcorr"].

  • figsize (tuple, optional) – Figure size (width, height). Defaults to None.

  • score_type (str, optional) – Standardization applied per channel pair. One of “z”, “zall”, “gz”, “modz”, “center”, or “none”. Defaults to “z”.

  • cmap (str, optional) – Colormap. Defaults to “bwr”.

  • triag (bool, optional) – Use only the upper triangle of each matrix. Defaults to True.

  • show_endfile (bool, optional) – Draw vertical lines at recording file boundaries. Defaults to False.

  • duration_name (str, optional) – Column holding each row’s duration. Defaults to “duration”.

  • endfile_name (str, optional) – Column holding each row’s end-of-file marker. Defaults to “endfile”.

plot_psd_histogram(
groupby: str = 'animalday',
figsize: tuple[float, float] | None = None,
avg_channels: bool = False,
plot_type: Literal['loglog', 'semilogy', 'semilogx', 'linear'] = 'loglog',
plot_slope=True,
xlim: tuple[float, float] | None = None,
**kwargs,
) → None[source]#

Plot the power spectrum per channel on log-log axes with a fitted slope.

Parameters:
  • groupby – Column to average over before plotting. Defaults to “animalday”.

  • figsize (tuple, optional) – Figure size (width, height). Defaults to None.

  • avg_channels (bool, optional) – Average across channels into one trace. Defaults to False.

  • plot_type – Matplotlib scaling to use. Defaults to “loglog”.

  • plot_slope – Currently unused.

  • xlim (tuple, optional) – Frequency axis limits. Defaults to None.

plot_psd_spectrogram(
multiindex: list[str] = ['animalday', 'animal', 'genotype'],
freq_range: tuple[float, float] = (1, 50),
center_stat: Literal['mean', 'median'] = 'mean',
mode: Literal['z', 'zall', 'gz', 'modz', 'center', 'none'] | None = 'z',
figsize: tuple[float, float] | None = None,
cmap: str = 'magma',
**kwargs,
) → None[source]#

Plot the power spectrum over time as a per-channel spectrogram.

Parameters:
  • multiindex – Index levels identifying each recording session.

  • freq_range (tuple, optional) – Frequency bounds in Hz. Defaults to (1, 50).

  • center_stat – Statistic used to collapse windows. Defaults to “mean”.

  • mode – Standardization applied to the spectrogram, the same vocabulary as score_type on the other methods. Defaults to “z”.

  • figsize (tuple, optional) – Figure size (width, height). Defaults to None.

  • cmap (str, optional) – Colormap. Defaults to “magma”.

plot_temporal_heatmap(
features: list[Literal['rms', 'ampvar', 'psdtotal', 'nspike', 'logrms', 'logampvar', 'logpsdtotal', 'lognspike', 'psdslope', 'psdband', 'psdfrac', 'logpsdband', 'logpsdfrac', 'cohere', 'zcohere', 'imcoh', 'zimcoh', 'pcorr', 'zpcorr']] | Literal['rms', 'ampvar', 'psdtotal', 'nspike', 'logrms', 'logampvar', 'logpsdtotal', 'lognspike', 'psdslope', 'psdband', 'psdfrac', 'logpsdband', 'logpsdfrac', 'cohere', 'zcohere', 'imcoh', 'zimcoh', 'pcorr', 'zpcorr'] | None = None,
figsize: tuple[float, float] | None = None,
cmap: str = 'viridis',
score_type: Literal['z', 'zall', 'gz', 'modz', 'center', 'none'] | None = None,
norm: Normalize | None = None,
component_norms: dict[str, Normalize] | None = None,
**kwargs,
) → None[source]#

Create temporal heatmap showing feature patterns over time.

Creates a heatmap where: - X-axis: Time of day (timestamp mod 24h) - Y-axis: Days - Color: Feature values (flattened across channels)

Parameters:
  • features – Feature names to plot. Histogram features are not supported, see neurodent.constants.analysis.FEATURES. Defaults to the linear features.

  • figsize (tuple, optional) – Figure size (width, height).

  • cmap (str, optional) – Colormap for the heatmap.

  • score_type (str, optional) – Standardization applied to feature values. One of “z”, “zall”, “gz”, “modz”, “center”, or “none”. Defaults to None.

  • norm (matplotlib.colors.Normalize, optional) – Normalization for the colormap. If None, uses default normalization. Common options are Normalize(vmin=0, vmax=1) for a fixed range, CenteredNorm(vcenter=0) to auto-detect a range around 0, and LogNorm() for a log scale.

  • component_norms (dict[str, matplotlib.colors.Normalize], optional) – Per-component color norms keyed by semantic label (e.g. “slope” / “intercept” for psdslope, or band names). A component listed here overrides norm for that component’s heatmap; components not listed fall back to norm. Useful when a multi-component feature’s components live on different scales.

  • **kwargs – Additional arguments passed to matplotlib.