rizer.spice.backend.services.results_plotting.export#
YAML annotation persistence and SVG export for the Results Explorer API.
Reads/writes the exact same axes:/annotations: YAML schema rizer.pipeline.plotting.plt_simulation.SimulationPlotter reads – so the two renderers stay visually consistent and a tuning session in the browser produces a YAML export-svg can immediately re-render with matplotlib into the same archived-figure format.
Functions#
|
Persist a tuned axes/annotations/arrows/trace_colors/trace_linestyles/text_positions block. |
Render traces/axes_config/annotations/arrows into one matplotlib figure. |
|
|
Save the given config, then render plot_kind into an SVG with matplotlib. |
Module Contents#
- rizer.spice.backend.services.results_plotting.export.save_annotations(plot_kind: str, run_ids: list[str], axes: dict[str, dict], annotations: list[dict], arrows: list[dict], trace_colors: dict[str, str], trace_linestyles: dict[str, str], text_positions: dict[str, float], comparison_name: str | None, time_offsets_ns: dict[str, float] | None = None, hidden_groups: list[str] | None = None, trace_sizes: dict[str, float] | None = None, trace_order: list[str] | None = None) pathlib.Path#
Persist a tuned axes/annotations/arrows/trace_colors/trace_linestyles/text_positions block.
text_positions (species name -> x) is merged into the existing texts: section’s x values rather than replacing it wholesale, unlike every other block here: texts: is also read by SimulationPlotter and, in production files, carries hand-authored comments and commented-out species entries (see test_save_annotations_preserves_comments_and_disabled_entries_elsewhere) that a full replace would silently destroy. time_offsets_ns (source_id -> ns), hidden_groups (curve-group ids), trace_sizes (style key -> line width or marker size, see _style_keys_for), and trace_order (style key or trace_id list, first = topmost – see _apply_trace_order) are written verbatim, like trace_colors/trace_linestyles – no merge logic needed, since all are simple values owned entirely by this feature.
- rizer.spice.backend.services.results_plotting.export.render_svg_from_plot_data(traces: list[rizer.spice.backend.services.results_plotting.traces.Trace], axes_config: dict[str, dict], annotations: list[dict], arrows: list[dict], hidden_groups: list[str], text_positions: dict[str, float] | None = None, show_legend: bool = True) tuple[matplotlib.figure.Figure, list[str]]#
Render traces/axes_config/annotations/arrows into one matplotlib figure.
One generic renderer that reads only the same Trace/axis-config shape build_plot_data produces for the live Plotly view: it handles any number of runs and any number of axes without a plot-kind-specific branch, applies each trace’s color/linestyle (a saved web-view override), and never requires a plot_annotations.yaml texts: entry keyed by a fixed label – avoiding a KeyError on export for plot kinds with no such entry (e.g. plot_plasma_radius/plot_power_repartition/ plot_temperatures_electric_field_full/plot_elastic_inelastic_power_ratio).
An on-curve tracking label is drawn only for a species-mole-fraction trace (via text_positions); every other plot kind’s fixed decorative labels (e.g. plasma_radius’s “Simulation”, power_repartition’s per-component labels) have no equivalent in this generic Trace model and are not reproduced – a legend is added instead so curve identity stays readable. The “change of radius” annotation plot_electron_density_vs_experiment draws is likewise absent: it was never part of annotations/arrows (see _build_electron_density_vs_experiment), so it never reaches this renderer either.
- Parameters:
axes_config (
dictofstrtodict) – Axis key -> PlotAxisConfig-shaped dict (label/xlim/ylim/xscale/yscale/color), as returned by build_plot_data.hidden_groups (
listofstr) – Curve-group ids to omit entirely – unlike the live Plotly view (which keeps a hidden group’s trace as a clickable “legendonly” legend entry), a static SVG has no such toggle, so a hidden group must not be drawn at all; its axis is dropped too if that group was the only thing on it.text_positions (
dictofstrtofloatorNone, optional) – Species name -> x position (ns) for its on-curve label. Traces with no matching entry (or no species) get no on-curve label.show_legend (
bool, optional) – If False, never draw a legend, even with labeled traces. Default True (matches the pre-existing behavior).
- Returns:
fig (
matplotlib.figure.Figure)warnings_raised (
listofstr) – Captured warnings.warn messages from validate_text_in_figure (an out-of-bounds annotation/text position being clamped).
- rizer.spice.backend.services.results_plotting.export.export_svg(plot_kind: str, run_ids: list[str], experiment_ids: list[str], axes: dict[str, dict], annotations: list[dict], arrows: list[dict], trace_colors: dict[str, str], trace_linestyles: dict[str, str], text_positions: dict[str, float], comparison_name: str | None, time_offsets_ns: dict[str, float] | None = None, hidden_groups: list[str] | None = None, show_legend: bool = True, trace_sizes: dict[str, float] | None = None, trace_order: list[str] | None = None) tuple[str, list[str], pathlib.Path]#
Save the given config, then render plot_kind into an SVG with matplotlib.
Renders from the same Trace/axis data build_plot_data builds for the live view (via _build_styled_plot_data, re-reading the config this call just persisted) through render_svg_from_plot_data. The renderer handles any number of runs and applies each trace’s color/linestyle/ size/render order directly. experiment_ids flows through the normal builder path, so the exported SVG overlays exactly the experiment files currently selected in the Results Explorer – not more, not less. time_offsets_ns/hidden_groups are applied here (shifting trace x-values, dropping hidden-group traces before rendering) since there is no client-side render step for a static SVG. trace_order is applied by _build_styled_plot_data (re-reading what this call just persisted) before render_svg_from_plot_data ever sees the traces, so it only needs to zorder them by list position. show_legend is a one-shot rendering preference for this export only – unlike everything else here, it is never persisted to plot_annotations.yaml. comparison_name is passed to _build_styled_plot_data too, not just save_annotations – for a 2+-run comparison, omitting it there would silently re-read an empty config instead of what was just saved (see _config_path_for_runs).
- Returns:
svg (
str) – The rendered SVG document.warnings_raised (
listofstr) – Any warnings.warn messages raised while rendering (e.g. a dragged label landing outside the configured axis limits and being clamped) – captured here because they would otherwise go to the server’s log, invisible to the browser.saved_path (
pathlib.Path) – Where the YAML config was written.