coco_pipe.viz.base#

Functions#

plot_bar(scores[, errors, labels, label_map, top_n, ...])

Plot a ranked bar chart with optional error bars.

centered_color_limits(values, *, center[, ...])

Return finite color limits symmetric around center.

accuracy_color_limits(values, *[, center, ...])

Return chance-centered color limits for accuracy-like values.

plot_heatmap(matrix[, x_labels, y_labels, cmap, ...])

Plot a 2D numeric matrix as a heatmap.

plot_line(x, y[, yerr, error_style, label, color, ...])

Plot a 2D line with optional uncertainty band or error bars.

plot_error_points(x, y[, xerr, yerr, labels, marker, ...])

Plot point estimates with optional x/y error bars and references.

plot_distribution_groups(groups, labels[, kind, ...])

Plot grouped scalar distributions as box or violin plots.

plot_histogram(values[, bins, color, title, xlabel, ...])

Plot a histogram of a 1D array of scalar values.

plot_scatter2d(x, y[, labels, label_map, palette, c, ...])

Scatter plot with optional class coloring.

plot_scatter3d(x, y, z[, labels, label_map, palette, ...])

3D scatter plot with optional class coloring.

plot_hexbin(x, y[, gridsize, cmap, mincnt, colorbar, ...])

Hexbin density plot for paired numeric values.

plot_streamfield(x_grid, y_grid, u_grid, v_grid[, ...])

Plot a 2D stream field from gridded vector components.

plot_topomap(values[, coords, index, info, vmin, ...])

Plot a topographic map for sensor values using MNE.

plot_timecourses(data, times[, channel_names, rois, ...])

Plot timecourses (ERPs, ERFs, source activations) across channels or ROIs.

plot_roi_sensors(container, rois[, palette, montage, ...])

Plot scalp topomaps highlighting specific Regions of Interest (ROIs).

Module Contents#

coco_pipe.viz.base.plot_bar(scores, errors=None, labels=None, label_map=None, top_n=None, ascending=False, sort=True, orientation='vertical', color=None, cmap=None, abs_values=False, title=None, xlabel=None, ylabel=None, figsize=None, ax=None, **_)#

Plot a ranked bar chart with optional error bars.

Parameters:
  • scores (pandas.Series | collections.abc.Mapping[str, float] | collections.abc.Sequence[float]) – Values to plot. Accepts a Series, {label: value} mapping, or a plain sequence.

  • errors (pandas.Series | collections.abc.Mapping[str, float] | collections.abc.Sequence[float] | None) – Optional symmetric error magnitudes aligned with scores.

  • labels (collections.abc.Sequence[str] | None) – Tick labels used when scores is a plain sequence.

  • label_map (collections.abc.Mapping[str, str] | None) – Optional {raw_label: display_label} mapping applied to tick labels.

  • top_n (int | None) – Keep only the first top_n entries after sorting.

  • ascending (bool) – Sort direction when sort=True.

  • sort (bool) – Whether to sort bars by value before plotting.

  • orientation (str) – "vertical" or "horizontal".

  • color (str | collections.abc.Sequence[str] | None) – Bar color or per-bar color sequence. Ignored when cmap is set.

  • cmap (str | None) – Colormap name used to derive per-bar colors from values.

  • abs_values (bool) – Plot and sort by absolute values while preserving the sign for errors.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • figsize (tuple[float, float] | None) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.centered_color_limits(values, *, center, minimum_half_range=0.0, bounds=None)#

Return finite color limits symmetric around center.

Parameters:
Return type:

tuple[float, float]

coco_pipe.viz.base.accuracy_color_limits(values, *, center=0.5, minimum_half_range=0.02)#

Return chance-centered color limits for accuracy-like values.

Parameters:
Return type:

tuple[float, float]

coco_pipe.viz.base.plot_heatmap(matrix, x_labels=None, y_labels=None, cmap=SEQUENTIAL, center=None, minimum_half_range=0.0, vmin=None, vmax=None, aspect='auto', origin=None, colorbar=True, colorbar_label=None, annotate=False, annotation_format='.3g', title=None, xlabel=None, ylabel=None, xtick_rotation=45, xtick_ha='right', figsize=None, ax=None, **_)#

Plot a 2D numeric matrix as a heatmap.

Parameters:
  • matrix (pandas.DataFrame | collections.abc.Sequence[collections.abc.Sequence[float]] | numpy.ndarray) – Values to display. A DataFrame provides default axis labels.

  • x_labels (collections.abc.Sequence[Any] | None) – Column tick labels. Overrides DataFrame column names.

  • y_labels (collections.abc.Sequence[Any] | None) – Row tick labels. Overrides DataFrame index.

  • cmap (str) – Colormap name.

  • center (float | None) – When set, a TwoSlopeNorm is applied so this value maps to the colormap midpoint. Limits are symmetric around the center unless both vmin and vmax are supplied.

  • minimum_half_range (float) – Minimum distance from center to either color limit.

  • vmin (float | None) – Explicit colormap lower bound.

  • vmax (float | None) – Explicit colormap upper bound.

  • aspect (str) – Passed directly to imshow.

  • origin (str | None) – Passed directly to imshow when not None.

  • colorbar (bool) – Whether to attach a colorbar.

  • colorbar_label (str | None) – Optional colorbar label.

  • annotate (bool) – Overlay each cell with its numeric value.

  • annotation_format (str) – Format string used for cell annotations.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • xtick_rotation (float) – X-tick label rotation in degrees.

  • xtick_ha (str) – X-tick label horizontal alignment.

  • figsize (tuple[float, float] | None) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_line(x, y, yerr=None, error_style='band', label=None, color=None, marker=None, linestyle=None, linewidth=2.0, alpha=1.0, band_alpha=0.15, title=None, xlabel=None, ylabel=None, legend=False, figsize=None, ax=None, **_)#

Plot a 2D line with optional uncertainty band or error bars.

Parameters:
  • x (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Horizontal axis values.

  • y (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Vertical axis values aligned with x.

  • yerr (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray | None) – Optional symmetric error magnitudes. Rendered as a shaded band or error bars depending on error_style.

  • error_style (str) – "band" for a filled fill_between region, "bar" for errorbar caps.

  • label (str | None) – Legend label.

  • color (Any | None) – Line and band color.

  • marker (str | None) – Matplotlib marker string.

  • linestyle (str | None) – Matplotlib linestyle string.

  • linewidth (float) – Line width in points.

  • alpha (float) – Line opacity.

  • band_alpha (float) – Opacity of the uncertainty band when error_style="band".

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • legend (bool) – Whether to show the legend.

  • figsize (tuple[float, float] | None) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_error_points(x, y, xerr=None, yerr=None, labels=None, marker='o', color=None, label=None, capsize=3.0, reference_x=None, reference_y=None, reference_style=None, title=None, xlabel=None, ylabel=None, xtick_rotation=45, xtick_ha='right', legend=False, figsize=None, ax=None, **_)#

Plot point estimates with optional x/y error bars and references.

Parameters:
  • x (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Horizontal positions of the points.

  • y (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Vertical positions of the points.

  • xerr (Any | None) – Optional horizontal error magnitudes passed to errorbar.

  • yerr (Any | None) – Optional vertical error magnitudes passed to errorbar.

  • labels (collections.abc.Sequence[Any] | None) – Tick labels placed at each x position.

  • marker (str) – Matplotlib marker string.

  • color (Any | None) – Point and error bar color.

  • label (str | None) – Legend label for the point series.

  • capsize (float) – Error bar cap size in points.

  • reference_x (float | None) – Draw a vertical dashed reference line at this x value.

  • reference_y (float | None) – Draw a horizontal dashed reference line at this y value.

  • reference_style (collections.abc.Mapping[str, Any] | None) – Optional style overrides for the reference lines.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • xtick_rotation (float) – X-tick label rotation in degrees.

  • xtick_ha (str) – X-tick label horizontal alignment.

  • legend (bool) – Whether to show the legend.

  • figsize (tuple[float, float] | None) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_distribution_groups(groups, labels, kind='box', show_points=True, jitter=0.15, point_color='black', point_alpha=0.55, point_size=18, showmeans=True, title=None, xlabel=None, ylabel=None, xtick_rotation=45, xtick_ha='right', figsize=None, ax=None, **_)#

Plot grouped scalar distributions as box or violin plots.

Parameters:
  • groups (collections.abc.Sequence[collections.abc.Sequence[float] | numpy.ndarray | pandas.Series]) – Sequence of data arrays, one per group. Non-finite values are dropped.

  • labels (collections.abc.Sequence[Any]) – Group labels aligned with groups.

  • kind (str) – "box" or "violin".

  • show_points (bool) – Overlay jittered individual points on top of the box or violin.

  • jitter (float) – Half-width of the jitter band around each group position.

  • point_color (str) – Color of the overlaid individual points.

  • point_alpha (float) – Opacity of the overlaid individual points.

  • point_size (float) – Size of the overlaid individual points.

  • showmeans (bool) – Whether to show the mean marker inside each box or violin.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • xtick_rotation (float) – X-tick label rotation in degrees.

  • xtick_ha (str) – X-tick label horizontal alignment.

  • figsize (tuple[float, float] | None) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_histogram(values, bins=30, color=None, title=None, xlabel=None, ylabel='Count', figsize=None, ax=None, **_)#

Plot a histogram of a 1D array of scalar values.

Parameters:
  • values (collections.abc.Sequence[float] | numpy.ndarray | pandas.Series) – Values to histogram. Non-finite values are dropped.

  • bins (int | collections.abc.Sequence[float]) – Number of bins, or explicit bin edges, passed to ax.hist.

  • color (str | None) – Bar color.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label (defaults to "Count").

  • figsize (tuple[float, float] | None) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_scatter2d(x, y, labels=None, label_map=None, palette=None, c=None, color=None, cmap=None, colorbar=False, colorbar_label='Value', xerr=None, yerr=None, reference_x=None, reference_y=None, reference_style=None, error_color='0.35', capsize=0.0, alpha=0.8, s=25.0, title=None, xlabel=None, ylabel=None, legend=True, legend_title=None, figsize=(5, 5), ax=None, **_)#

Scatter plot with optional class coloring.

Parameters:
  • x (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Horizontal coordinates.

  • y (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Vertical coordinates.

  • labels (pandas.Series | collections.abc.Sequence[Any] | numpy.ndarray | None) – Discrete class labels used to color points. When provided, color and c are ignored and each class gets its own legend entry.

  • label_map (collections.abc.Mapping[Any, str] | None) – Optional {raw_label: display_label} mapping for the legend.

  • palette (collections.abc.Sequence[str] | None) – Explicit per-class color sequence, overriding the default qualitative palette.

  • c (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray | None) – Continuous scalar values used for colormap encoding when labels is None.

  • color (Any | None) – Single color for all points when neither labels nor c is set.

  • cmap (str | None) – Colormap name used with c.

  • colorbar (bool) – Whether to attach a colorbar when c is provided.

  • colorbar_label (str) – Optional colorbar label.

  • xerr (Any | None) – Optional horizontal error magnitudes.

  • yerr (Any | None) – Optional vertical error magnitudes.

  • reference_x (float | None) – Draw a vertical dashed reference line at this x value.

  • reference_y (float | None) – Draw a horizontal dashed reference line at this y value.

  • reference_style (collections.abc.Mapping[str, Any] | None) – Optional style overrides for the reference lines.

  • error_color (str) – Color of the error bars.

  • capsize (float) – Error bar cap size.

  • alpha (float) – Point opacity.

  • s (float) – Point marker size.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • legend (bool) – Whether to show the class legend.

  • legend_title (str | None) – Optional legend title.

  • figsize (tuple[float, float]) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_scatter3d(x, y, z, labels=None, label_map=None, palette=None, c=None, color=None, cmap=None, colorbar=False, colorbar_label='Value', alpha=0.8, s=25.0, title=None, xlabel=None, ylabel=None, zlabel=None, legend=True, legend_title=None, figsize=(5, 5), ax=None, **_)#

3D scatter plot with optional class coloring.

Parameters:
Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_hexbin(x, y, gridsize=40, cmap=SEQUENTIAL, mincnt=1, colorbar=True, colorbar_label=None, reference_identity=False, reference_style=None, title=None, xlabel=None, ylabel=None, legend=False, figsize=(5, 5), ax=None, **_)#

Hexbin density plot for paired numeric values.

Parameters:
  • x (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Horizontal values.

  • y (pandas.Series | collections.abc.Sequence[float] | numpy.ndarray) – Vertical values aligned with x.

  • gridsize (int) – Number of hexagons in the horizontal direction.

  • cmap (str) – Colormap name encoding bin counts.

  • mincnt (int | None) – Minimum count per bin required to display a hexagon.

  • colorbar (bool) – Whether to attach a colorbar.

  • colorbar_label (str | None) – Optional colorbar label.

  • reference_identity (bool) – Overlay a dashed red identity line (y = x).

  • reference_style (collections.abc.Mapping[str, Any] | None) – Optional style overrides for the identity reference line.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • legend (bool) – Whether to show the legend.

  • figsize (tuple[float, float]) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_streamfield(x_grid, y_grid, u_grid, v_grid, points=None, density=1.5, cmap=SEQUENTIAL, colorbar_label=None, point_color='#DDDDDD', point_size=15, point_alpha=0.6, title=None, xlabel=None, ylabel=None, figsize=(5, 5), ax=None, **_)#

Plot a 2D stream field from gridded vector components.

Parameters:
  • x_grid (numpy.ndarray) – 2D grid of x-coordinates produced by np.meshgrid.

  • y_grid (numpy.ndarray) – 2D grid of y-coordinates produced by np.meshgrid.

  • u_grid (numpy.ndarray) – Horizontal velocity component on the same grid.

  • v_grid (numpy.ndarray) – Vertical velocity component on the same grid.

  • points (numpy.ndarray | None) – Optional (N, 2) array of raw data points scattered beneath the streamlines.

  • density (float) – Streamline density passed to matplotlib.axes.Axes.streamplot.

  • cmap (str) – Colormap used to encode local flow speed along streamlines.

  • colorbar_label (str | None) – Optional colorbar label.

  • point_color (str) – Color for the optional raw data scatter points.

  • point_size (float) – Marker size for raw data scatter points.

  • point_alpha (float) – Opacity of raw data scatter points.

  • title (str | None) – Optional axes title.

  • xlabel (str | None) – Optional x-axis label.

  • ylabel (str | None) – Optional y-axis label.

  • figsize (tuple[float, float]) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (Any)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_topomap(values, coords=None, index=None, info=None, vmin=None, vmax=None, cmap=None, sensors='markers', outlines=True, contours=0, symmetric=True, title=None, cbar=True, cbar_label=None, figsize=(5, 5), ax=None, **_)#

Plot a topographic map for sensor values using MNE.

Parameters:
  • values (pandas.Series | collections.abc.Mapping[str, float] | collections.abc.Sequence[float]) – Sensor values to plot. A Series or mapping must be keyed by sensor name; a plain sequence requires index or coords/info to supply the names.

  • coords – Sensor coordinate source: an MNE-style (N, 2+) array, a {name: (x, y)} mapping, or a DataFrame with x and y columns and sensor names in the index or a FeatureName / Sensor column.

  • index (collections.abc.Sequence[str] | None) – Explicit sensor name list used when values is a plain sequence.

  • info – MNE Info object from which electrode positions are extracted. Takes priority over coords.

  • vmin (float | None) – Colormap lower bound. Computed symmetrically when symmetric=True.

  • vmax (float | None) – Colormap upper bound. Computed symmetrically when symmetric=True.

  • cmap (str | None) – Colormap name. Defaults to the diverging theme map when symmetric=True, otherwise the sequential map.

  • sensors (str) – "markers" to show sensor dots, "labels" to annotate each sensor, or "none" to hide sensors.

  • outlines (bool) – Whether to draw the head outline.

  • contours (int) – Number of contour lines drawn over the topomap.

  • symmetric (bool) – Derive vmin/vmax symmetrically around zero.

  • title (str | None) – Optional axes title.

  • cbar (bool) – Whether to attach a colorbar.

  • cbar_label (str | None) – Optional colorbar label.

  • figsize (tuple[float, float]) – Figure size used when creating new axes.

  • ax (matplotlib.pyplot.Axes | None) – Existing Matplotlib axes to draw into.

  • _ (object)

Returns:

The created or reused figure and axes.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]

coco_pipe.viz.base.plot_timecourses(data, times, channel_names=None, rois=None, group_labels=None, group_name_map=None, palette=None, linestyle_map=None, n_cols=None, error_style='band', xlabel='Time', ylabel='Amplitude', title=None, figsize=None, sharey=True, sharex=True, add_zero=False, axes_kws=None, **kwargs)#

Plot timecourses (ERPs, ERFs, source activations) across channels or ROIs.

Parameters:
  • data (numpy.ndarray | pandas.DataFrame) – Shape (n_trials, n_channels, n_times) or (n_channels, n_times).

  • times (numpy.ndarray) – Time axis values, shape (n_times,).

  • channel_names (collections.abc.Sequence[str] | None) – Names of the channels in data. Required if rois specifies channel names. If data is (n_channels, n_times) and channel_names is omitted, channels are numbered.

  • rois (collections.abc.Mapping[str, collections.abc.Sequence[str]] | collections.abc.Sequence[str] | None) – Mapping of {roi_name: [channel_names]} to average over. If a sequence of strings is provided, each string is treated as a single-channel ROI. If None, all channels are plotted individually.

  • group_labels (collections.abc.Sequence[Any] | None) – Shape (n_trials,) assigning each trial to a group. If None, all trials are averaged together.

  • group_name_map (collections.abc.Mapping[Any, str] | None) – Mapping to rename groups for the legend.

  • palette (collections.abc.Mapping[Any, Any] | collections.abc.Sequence[Any] | None) – Color mapping for groups. Can be a dictionary or a list of colors.

  • linestyle_map (collections.abc.Mapping[Any, str] | None) – Linestyle mapping for groups.

  • n_cols (int | None) – Maximum number of columns for the subplot grid.

  • error_style (str) – “band” (shaded SEM) or “bar” (errorbars). Passed to plot_line.

  • xlabel (str) – X-axis label.

  • ylabel (str) – Y-axis label.

  • title (str | None) – Figure title.

  • figsize (tuple[float, float] | None) – Custom figure size.

  • sharey (bool) – Whether to share axes across subplots.

  • sharex (bool) – Whether to share axes across subplots.

  • add_zero (bool) – Whether to add reference lines at Time=0 and Amplitude=0.

  • axes_kws (dict | None) – Dictionary of keyword arguments passed to finalize_axes (e.g. grid=False).

  • kwargs (Any) – Additional arguments passed to plot_line.

Returns:

Figure and axes array.

Return type:

tuple[matplotlib.figure.Figure, np.ndarray]

coco_pipe.viz.base.plot_roi_sensors(container, rois, palette=None, montage='standard_1005', figsize=None, axes_kws=None)#

Plot scalp topomaps highlighting specific Regions of Interest (ROIs).

Parameters:
  • container (Any) – The DataContainer containing the channel coordinates.

  • rois (collections.abc.Mapping[str, collections.abc.Sequence[str]]) – A dictionary mapping ROI names to lists of channel names.

  • palette (collections.abc.Sequence[Any] | None) – A list of colors to use for highlighting each ROI. If None, uses the default colorblind palette.

  • montage (str | Any) – The MNE montage to use for plotting sensors. Can be a string name of a standard montage (e.g. ‘standard_1005’) or an mne.channels.DigMontage object.

  • figsize (tuple[float, float] | None) – Figure size. If None, automatically scaled based on the number of ROIs.

  • axes_kws (dict | None) – Additional keyword arguments passed to finalize_axes.

Returns:

The matplotlib Figure and Axes array.

Return type:

fig, axes