astrocook.plotting module#

Plots of a session without the GUI (phase 6-ter, PR 3): for the MCP server, which shows them to an agent as images, and for scripts (e.g. in a notebook).

Matplotlib’s Figure is used directly, without pyplot: no backend and no display are needed, so the plots work in the headless Docker image of the server (no PySide6). The colours of the plots of the GUI are defined here (moved from gui/plot_style.py, which imports them), so that the two look alike.

astrocook.plotting.ERROR_COLOR = '#aaaaaa'#

The error of the flux (band, line or bars), in every plot

astrocook.plotting.HI_TICK_COLOR = '#d62728'#

a softer red than pure red, drawn translucent (the standard palette, PLOT_PALETTES)

Type:

The ticks of the HI components on the main plot

astrocook.plotting.PLOT_PALETTES = {'colorblind': {'cursor': '#56b4e9', 'flag_bound': '#cc79a7', 'flag_nan': '#d55e00', 'flux': '#333333', 'hi_ticks': '#d55e00', 'model': '#0072b2', 'model_alpha': 0.9, 'model_lw': 1.1, 'residuals': '#d55e00'}, 'standard': {'cursor': '#e377c2', 'flag_bound': '#9467bd', 'flag_nan': '#d62728', 'flux': '#1f77b4', 'hi_ticks': '#d62728', 'model': '#2ca02c', 'model_alpha': 0.9, 'model_lw': 1.1, 'residuals': '#ff0000'}}#

The palettes of the plots, chosen in View > Plot Colours (phase 5-bis): “standard”, the colours of 2.2.0 with a thinner model (lw 1.6 -> 1.1: the thick model covered the data in the forest), and “colorblind”, from the Okabe-Ito palette, whose blue model, dark spectrum and orange selection stay apart for every type of colour blindness (in the standard palette, model, selection and residuals of the velocity plot become one olive for a deuteranope). The selection (theme.SELECTION, an amber close to the orange of Okabe-Ito) is the same in both: it is shared with the widgets. Compared on the “My QSO” session with simulations of colour blindness (Machado et al. 2009) before the choice (Guido).

astrocook.plotting.CONTINUUM_COLOR = 'black'#

The continuum, as in the main plot of the GUI

astrocook.plotting.plot_spectrum(session, x_min: float | None = None, x_max: float | None = None, normalized: bool = False, palette: str = 'standard')[source]#

A figure of the spectrum of a session in a range of x.

The flux and its error, the continuum and the model (if any), and a tick at each line of each component, labelled with its series (the HI series in the colour of the HI ticks of the GUI).

Parameters:
  • session (Session)

  • x_min (float, optional) – The range, in the unit of x; None: the start (end) of the spectrum.

  • x_max (float, optional) – The range, in the unit of x; None: the start (end) of the spectrum.

  • normalized (bool, optional) – Divide by the continuum, if there is one.

  • palette (str, optional) – 'standard' or 'colorblind' (PLOT_PALETTES).

Return type:

matplotlib.figure.Figure

Raises:

ValueError – If the range is empty or outside the spectrum.

astrocook.plotting.figure_png(fig) → bytes[source]#

A figure as PNG bytes.