Plotting API¶
Import shared plotting utilities from imvpy.utils. Plotting functions apply the
IMV visual system locally; style configuration functions let custom Matplotlib
figures use the same choices.
Constants¶
| Name | Value | Meaning |
|---|---|---|
COLORMAP |
"imv" |
Registered navy-to-red continuous colormap |
DISPLAY_DPI |
110 |
Default interactive figure resolution |
FIGURE_DPI |
800 |
Default raster and rasterized-artist resolution |
FIGURE_FORMATS |
("png", "pdf", "svg") |
Formats emitted by save_figure |
PALETTE_COLORS |
named colors | Canonical red, cream, blue, navy, and green values |
PAPER_STYLE |
dict |
Canonical publication rcParams |
Style configuration¶
imvpy.utils.plotting.rc_params
¶
Return publication-style Matplotlib parameters without applying them.
Keyword overrides are layered over the canonical defaults. Keys containing
periods can be passed by expanding a dictionary, for example
rc_params(**{"axes.grid": False}).
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.plotting_context
¶
Return a scoped Matplotlib context using the IMV publication style.
Example
import matplotlib.pyplot as plt with plotting_context(): ... figure, axis = plt.subplots()
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.configure_plotting
¶
Apply the IMV publication style globally and return applied settings.
Prefer :func:plotting_context in reusable applications because this
function intentionally mutates Matplotlib's process-wide rcParams.
Source code in src/imvpy/utils/plotting.py
Palette helpers¶
imvpy.utils.plotting.spectral_colors
¶
Return evenly spaced categorical colors from the canonical IMV ramp.
Parameters:
-
count(int) –Positive number of colors.
Returns:
-
ndarray–An
(count, 4)array of RGBA colors.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.categorical_colors
¶
imvpy.utils.plotting.sequential_cmap
¶
Panel helpers¶
imvpy.utils.plotting.figure_size
¶
Return manuscript figure dimensions for a regular panel grid.
Parameters:
-
n_rows(int, default:1) –Positive number of rows.
-
n_cols(int, default:1) –Positive number of columns.
-
width(float, default:PANEL_WIDTH) –Width of each panel in inches.
-
height(float, default:PANEL_HEIGHT) –Height of each panel in inches.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.label_panels
¶
Label data axes a., b., ... in bold row-major order.
Pass data axes explicitly rather than figure.axes so colorbars are not
labelled. Existing centered and right-aligned titles are cleared.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.style_axis
¶
Apply the IMV frame, ticks, and dashed grid to a Cartesian axis.
Parameters:
-
axis(Axes) –Axis to style in place.
-
grid_axis({'x', 'y', 'both', None}, default:'y') –Direction in which to draw grid lines. Pass
Noneto disable the grid.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.apply_tight_layout
¶
Fit panels, inset colorbars, and bottom figure legends inside a figure.
Source code in src/imvpy/utils/plotting.py
Bar helpers¶
imvpy.utils.plotting.bar_style
¶
Return canonical keyword arguments for bars with error bars.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.annotate_bars
¶
Label vertical bar values beyond their error caps, including negatives.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.plot_bars
¶
plot_bars(axis, x, values, *, yerr=None, colors=None, width=0.8, annotation_fontsize=ANNOTATION_FONT_SIZE)
Draw annotated, black-edged vertical bars in the IMV publication style.
Use :func:set_bar_limits after plotting all axes in a shared-y row so
labels and error caps receive consistent headroom.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.set_bar_limits
¶
Add shared headroom beyond bar/error extents without resizing axes.
Source code in src/imvpy/utils/plotting.py
Heatmap helpers¶
imvpy.utils.plotting.heatmap_style
¶
Return canonical seaborn options for an annotated IMV heatmap.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.style_heatmap_frame
¶
Show a thin black frame around a heatmap and remove Cartesian grids.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.style_heatmap_axes
¶
Frame a heatmap and repeat its class labels on opposing edges.
Source code in src/imvpy/utils/plotting.py
imvpy.utils.plotting.add_heatmap_colorbar
¶
Add a full-height vector colorbar without resizing sibling panels.
Source code in src/imvpy/utils/plotting.py
Matrix heatmap¶
imvpy.utils.plotting.plot_imv_heatmap
¶
plot_imv_heatmap(matrix, *, ax=None, figsize=(6, 6), title='IMV matrix', labels: Sequence[str] | None = None, fmt='.3f', cmap=COLORMAP, center=None, colorbar_label='IMV')
Plot a square IMV matrix using the canonical publication heatmap.
Parameters:
-
matrix(array - like) –Non-empty square numeric matrix. When this is a pandas DataFrame, its column names become labels by default.
-
ax(Axes, default:None) –Existing axis. A new figure and axis are created when omitted.
-
figsize(tuple[float, float], default:(6, 6)) –New figure size in inches. Ignored when
axis supplied. Default:(6, 6). -
title(str, default:'IMV matrix') –Bold, left-aligned axis title.
-
labels(Sequence[str], default:None) –Shared row and column labels. Must have one item per matrix dimension. DataFrame columns are used when omitted.
-
fmt(str, default:'.3f') –Seaborn annotation format. Default:
".3f". -
cmap(str or Colormap, default:COLORMAP) –Color map. Defaults to the navy-to-red
"imv"map. -
center(float, default:None) –Value placed at the neutral cream midpoint. Use
0for directional matrices containing negative values. -
colorbar_label(str, default:'IMV') –Colorbar label. Default:
"IMV".
Returns:
-
tuple or Axes–(figure, axis)for a newly created axis, otherwise the supplied axis.
Raises:
-
ValueError–If the matrix is empty or not square, or label count does not match its dimension.
Source code in src/imvpy/utils/plotting.py
One-vs-rest boxplot¶
imvpy.utils.plotting.plot_ova_boxplot
¶
plot_ova_boxplot(fold_scores, *, ax=None, figsize=(6, 6), labels=None, title='One-vs-rest IMV across folds', ylabel='IMV')
Plot fold-level one-vs-rest IMV distributions in publication style.
Parameters:
-
fold_scores(array - like) –Non-empty folds-by-classes numeric matrix.
-
ax(Axes, default:None) –Existing axis. A new figure and axis are created when omitted.
-
figsize(tuple[float, float], default:(6, 6)) –New figure size in inches. Ignored when
axis supplied. Default:(6, 6). -
labels(Sequence[str], default:None) –One label per class. Generic outcome labels are generated when omitted.
-
title(str, default:'One-vs-rest IMV across folds') –Bold, left-aligned axis title.
-
ylabel(str, default:'IMV') –Vertical axis label. Default:
"IMV".
Returns:
-
tuple or Axes–(figure, axis)for a newly created axis, otherwise the supplied axis.
Raises:
-
ValueError–If scores are not a non-empty two-dimensional matrix or the label count does not match the class count.
Source code in src/imvpy/utils/plotting.py
Ablation heatmap¶
imvpy.utils.plotting.plot_ablation_matrix
¶
Plot a directional model-ablation matrix in the IMV visual style.
Parameters:
-
matrix(array - like) –Input forwarded to :func:
plot_imv_heatmap. -
**kwargs(object, default:{}) –Additional heatmap options. By default zero is placed at the palette's neutral midpoint and the colorbar is labelled
"Directional IMV".
Returns:
-
tuple or Axes–The return value from :func:
plot_imv_heatmap.
Source code in src/imvpy/utils/plotting.py
Multi-format export¶
imvpy.utils.plotting.save_figure
¶
Save a figure as 800-DPI PNG, PDF, and SVG files.
destination may be a bare basename or end in one of the supported
extensions; in either case all three sibling files are written. The DPI is
also passed to vector backends so any rasterized artists use the same output
resolution.
Parameters:
-
figure(Figure) –Figure exposing
savefig. -
destination(path - like) –Output basename, optionally ending in
.png,.pdf, or.svg. Parent directories are created. -
dpi(int or float, default:FIGURE_DPI) –Positive output resolution. Default: 800.
-
bbox_inches(str, default:'tight') –Matplotlib bounding-box mode. Default:
"tight". -
**savefig_kwargs(object, default:{}) –Additional keyword arguments forwarded to every
figure.savefigcall.
Returns:
-
dict[str, Path]–Paths keyed by
"png","pdf", and"svg".
Raises:
-
ValueError–If
dpiis not a finite positive number.