striqt.figures.backend¶
The plot backend protocol and its matplotlib and plotly implementations.
plotting backends that draw the figures of each data variable.
MatplotlibBackend
¶
MatplotlibBackend(
opts: SharedPlotOptions,
output_dir: Path | None,
*,
interactive: bool | str | None = None,
lock: RLock | None = None,
)
Bases: PlotBackend['xarray.plot.FacetGrid']
a plotting backend that draws with matplotlib, one FacetGrid per figure.
Each drawing method lays out the facets from opts and returns the grid. An
image or line of more than 10000 values, and every band, is rasterized. A line
drawn onto a target adds no legend entry.
Parameters:
-
opts(SharedPlotOptions) –the facet layout and label formats of every figure
-
output_dir(Path | None) –the directory for the figure files;
Nonewrites no file -
interactive(bool | str | None, default:None) –True leaves pyplot interactive after each
finish; aTerminalGraphicsname shows each figure in the terminal; False orNonedoes neither -
lock(RLock | None, default:None) –serializes the terminal image writes across processes;
Nonelocks nothing
output_dir
instance-attribute
¶
the directory of the figure files written by finish; None writes no file
interactive
instance-attribute
¶
True leaves pyplot interactive after finish; a TerminalGraphics name
shows each figure in the terminal; False or None does neither
lock
instance-attribute
¶
serializes the terminal image writes of finish across processes
last_grid
class-attribute
instance-attribute
¶
the grid of the most recent finish call, or None before the first
finish
¶
label target from the attrs of the drawn data and the formats of opts.
With output_dir set, the figure file named by opts.filename_fmt is written
there at the dpi between 120 and 300 that resolves each sample of the drawn
data, and a record is logged on the analysis logger at INFO. Interactive
pyplot mode is turned on when interactive is True. The figure is shown in
the terminal and closed when interactive names a terminal graphics
protocol. target is kept as last_grid.
Parameters:
-
target(FacetGrid) –the grid returned by a drawing method of this backend
-
xticklabelunits(bool | Literal['auto'], default:'auto') –whether each x tick label ends with the units;
'auto'selects True for aunitsattr of 1 or 2 characters
Returns:
-
Path | None–the path of the figure file, or
Nonewhenoutput_dirisNone
PlotBackend
¶
Bases: Protocol[T]
the drawing methods of a plotting backend with grid type T.
An implementation lays out one grid of facets per drawing call from the col,
row, and col_wrap fields of opts, and returns the grid. A later call with
that grid as target draws onto the same facets, and finish labels the grid.
opts
instance-attribute
¶
the facet layout and label formats shared by every figure
line
¶
line(
data: DataArray,
*,
x: str,
hue: str | None = None,
yscale: ScaleOptions = 'linear',
sharex: bool = True,
ylim: tuple[float | None, float | None] | None = None,
step: StepStyle | None = None,
target: T | None = None,
) -> T
draw one line per hue value of data on each facet.
Parameters:
-
data(DataArray) –the values on the y axis, with dimensions
x,hue(when set), and the facet dimensions ofopts -
x(str) –the dimension or coordinate of
dataon the x axis -
hue(str | None, default:None) –the dimension of
datathat selects one line per value, with a legend;Nonedraws one line per facet -
yscale(ScaleOptions, default:'linear') –the y axis scale,
'linear'or'log' -
sharex(bool, default:True) –whether the facets share x limits
-
ylim(tuple[float | None, float | None] | None, default:None) –the y limits;
Nonein either position leaves that limit to the data extent -
step(StepStyle | None, default:None) –the placement of the step between samples when each value is held until the next sample;
Noneconnects the samples -
target(T | None, default:None) –Nonebuilds a new grid; the lines are drawn onto a grid returned by an earlier call of this backend, with facet coordinates equal to those ofdata
Returns:
-
T–the new grid, or
targetwhen given
Raises:
-
ValueError–if
targetis a grid with facets thatdatadoes not have
fill_between
¶
fill_between(
low: DataArray,
high: DataArray,
*,
x: str,
hue: str | None = None,
alpha: float = 0.25,
step: StepStyle | None = None,
target: T | None = None,
) -> T
shade the band from low to high per hue value on each facet.
A band and a line drawn with the same hue value on one grid have the same
color.
Parameters:
-
low(DataArray) –the lower edge of the band, with dimensions
x,hue(when set), and the facet dimensions ofopts -
high(DataArray) –the upper edge of the band, with the dimensions of
low -
x(str) –the dimension or coordinate of
lowandhighon the x axis -
hue(str | None, default:None) –the dimension that selects one band per value;
Noneshades one band per facet -
alpha(float, default:0.25) –the opacity of the band, in [0, 1]
-
step(StepStyle | None, default:None) –the placement of the step between samples when each edge is held until the next sample;
Noneconnects the samples -
target(T | None, default:None) –Nonebuilds a new grid; the bands are drawn onto a grid returned by an earlier call of this backend, with facet coordinates equal to those oflow
Returns:
-
T–the new grid, or
targetwhen given
Raises:
-
ValueError–if
targetis a grid with facets thatlowdoes not have
heatmap
¶
heatmap(
data: DataArray,
*,
x: str,
y: str,
cmap: str = 'cubehelix',
vmin: float | None = None,
vmax: float | None = None,
vstep: float | None = None,
) -> T
draw data as a color image with a colorbar on each facet.
Parameters:
-
data(DataArray) –the values mapped to color, with dimensions
x,y, and the facet dimensions ofopts -
x(str) –the dimension or coordinate of
dataon the x axis -
y(str) –the dimension or coordinate of
dataon the y axis -
cmap(str, default:'cubehelix') –a matplotlib colormap name
-
vmin(float | None, default:None) –the value at the low end of the colormap;
Noneselects the data minimum -
vmax(float | None, default:None) –the value at the high end of the colormap;
Noneselects the data maximum -
vstep(float | None, default:None) –the width (in the units of
data) of the color bands that quantize the colormap betweenvminrounded down andvmaxrounded up to multiples ofvstep;Nonemaps colors continuously
Returns:
-
T–a new grid
finish
¶
label target from the attrs of the drawn data and the formats of opts.
Parameters:
-
target(T) –the grid returned by a drawing method of this backend
-
xticklabelunits(bool | Literal['auto'], default:'auto') –whether each x tick label ends with the units;
'auto'leaves the choice to the backend
Returns:
-
Path | None–the path of the saved figure file, or
Nonewhen no file is written
limit_facets
¶
set the x limits of each facet of target to (low, high).
Parameters:
-
target(T) –the grid to limit
-
low(DataArray | float | None) –the lower limit, or a DataArray with one value per facet;
Noneleaves the lower limit to the data extent -
high(float | None) –the upper limit;
Noneleaves the upper limit to the data extent
mark_noise_level
¶
mark_noise_level(
data: Dataset,
var_name: str,
grid: T,
where: Literal['x', 'y', 'colorbar'],
) -> None
draw the system noise level (in dBm) for var_name on each facet of grid.
The level is system_noise in the noise bandwidth of var_name, drawn on
each facet at the entry for the coordinate value of that facet. Nothing is
drawn when data has no system_noise variable or var_name has no noise
bandwidth.
Parameters:
-
data(Dataset) –the dataset with the
system_noisevariable (dBm/Hz) andvar_name -
var_name(str) –the data variable or power-bin coordinate that sets the noise bandwidth
-
grid(T) –the grid to draw on
-
where(Literal['x', 'y', 'colorbar']) –'x'draws a horizontal line for power on the y axis,'y'a vertical line for power on the x axis, and'colorbar'a mark on the colorbar of a heatmap
Raises:
-
TypeError–if
whereis'colorbar'andgridhas no colorbar, or ifwhereis none of the 3 values
PlotlyBackend
¶
Bases: PlotBackend['go.Figure']
the plotting backend that draws go.Figure grids for the browser.
Each drawing call without target appends one figure to a pending list that
get_plot_data returns and clears. The color limits of heatmap and the y
limits of line and fill_between widen across calls and narrow only at
reset. sharex has no effect.
batch_term_images
¶
buffer the terminal graphics written in the context and emit the batch on exit.
The standard output of the block is collected and written as one payload; for the kitty protocol, a delete-all-images command and a cursor-home escape precede the payload, so the images of the block replace the previous ones.
coerce_column
¶
coerce_column(data: _T, plotter: PlotBackend[Any]) -> _T
add the size-1 facet dimension _view to data of an unfaceted plot.
A plot is unfaceted when plotter.opts sets neither col nor row. With col
or row set, data is returned unchanged.
select_mpl_backend
¶
select a matplotlib backend, with the terminal style when interactive is set.
Interactive pyplot mode is turned off.
Parameters:
-
style(str | None) –a matplotlib style name, or None; the terminal style is applied after it when
interactiveis set -
interactive(TerminalGraphics | None) –'sixel','kitcat', or'kitty'selects a terminal graphics backend; None selects'agg'
Raises:
-
ValueError–if
interactiveis none of None,'sixel','kitcat', or'kitty'
term_graphics_notice
¶
print the terminal requirements of the graphics protocol interactive.
Nothing is printed for None.