plesty.lib.report.svg
A figure’s drawables as one self-contained SVG.
Series take their colours from the packaged palette (the same tokens a live
view resolves), and everything else — axes, ticks, labels — is drawn in
currentColor, so the figure reads on the page it is set in, light or dark.
An Image is embedded as a PNG in the
palette’s colour map; nothing outside the standard library and numpy is needed
to draw any of it.
Attributes
Functions
|
Draw drawables on one pair of axes. |
|
Return the finite entries of values as a flat float array. |
|
Return the range covering every array, widened when it is a point. |
|
Return the x and y ranges the axes show. |
|
Return round tick positions inside |
|
Return a tick value with just the decimals its step needs. |
|
Return a function from data coordinates to SVG coordinates. |
|
Draw the frame, the ticks with their values, and the axis labels. |
|
Draw a line (broken where a value is missing) or a set of points. |
|
Return one unbroken run of a line. |
|
Return the traces a legend lists: labelled, and not hidden by a |
|
Return the box |
|
Choose the corner where the legend covers the fewest trace points. |
|
List every labelled trace in corner of the plot. |
|
Set scalars and text marks in the top-left corner, one line each. |
|
Return the image scaled to |
|
Map levels in |
|
Encode an |
|
Return a PNG as a |
|
Embed the image, first row at the bottom, stretched over its extent. |
|
Draw the colour map beside the plot, labelled with the image's range. |
Module Contents
- plesty.lib.report.svg.MARGIN = (64, 20, 16, 48)
- plesty.lib.report.svg.Trace
- plesty.lib.report.svg.figure_svg(drawables: Sequence[plesty.lib.monitor.plots.Drawable], theme: plesty.lib.ui.theme.Theme | None = None) str
Draw drawables on one pair of axes.
- Parameters:
drawables (Sequence[plesty.lib.monitor.plots.Drawable]) – What to draw, in the order it is layered.
theme (Optional[plesty.lib.ui.theme.Theme]) – Where colour tokens resolve; the packaged palette by default.
- Returns:
An
<svg>element.- Return type:
str
- plesty.lib.report.svg._finite(values: Any) numpy.ndarray
Return the finite entries of values as a flat float array.
- Parameters:
values (Any)
- Return type:
numpy.ndarray
- plesty.lib.report.svg._span(values: Sequence[numpy.ndarray]) tuple[float, float]
Return the range covering every array, widened when it is a point.
- Parameters:
values (Sequence[numpy.ndarray])
- Return type:
tuple[float, float]
- plesty.lib.report.svg._ranges(images: Sequence[plesty.lib.monitor.plots.Image], traces: Sequence[Trace]) tuple[tuple[float, float], tuple[float, float]]
Return the x and y ranges the axes show.
- Parameters:
images (Sequence[plesty.lib.monitor.plots.Image])
traces (Sequence[Trace])
- Return type:
tuple[tuple[float, float], tuple[float, float]]
- plesty.lib.report.svg._ticks(low: float, high: float, count: int = 6) list[float]
Return round tick positions inside
[low, high]: steps of 1, 2 or 5.- Parameters:
low (float)
high (float)
count (int)
- Return type:
list[float]
- plesty.lib.report.svg._tick_label(value: float, ticks: Sequence[float]) str
Return a tick value with just the decimals its step needs.
- Parameters:
value (float)
ticks (Sequence[float])
- Return type:
str
- plesty.lib.report.svg._mapper(area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float]) Any
Return a function from data coordinates to SVG coordinates.
- Parameters:
area (tuple[float, float, float, float])
x_range (tuple[float, float])
y_range (tuple[float, float])
- Return type:
Any
- plesty.lib.report.svg._axes(area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float], drawables: Sequence[plesty.lib.monitor.plots.Drawable]) str
Draw the frame, the ticks with their values, and the axis labels.
- Parameters:
area (tuple[float, float, float, float])
x_range (tuple[float, float])
y_range (tuple[float, float])
drawables (Sequence[plesty.lib.monitor.plots.Drawable])
- Return type:
str
- plesty.lib.report.svg._trace(item: Trace, area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float], theme: plesty.lib.ui.theme.Theme) str
Draw a line (broken where a value is missing) or a set of points.
- Parameters:
item (Trace)
area (tuple[float, float, float, float])
x_range (tuple[float, float])
y_range (tuple[float, float])
theme (plesty.lib.ui.theme.Theme)
- Return type:
str
- plesty.lib.report.svg._polyline(points: list[str], colour: str, width: float) str
Return one unbroken run of a line.
- Parameters:
points (list[str])
colour (str)
width (float)
- Return type:
str
- plesty.lib.report.svg._CORNERS = ('top-right', 'bottom-right', 'top-left', 'bottom-left')
- plesty.lib.report.svg._legend_entries(traces: Sequence[Trace]) list[Trace]
Return the traces a legend lists: labelled, and not hidden by a
_label.
- plesty.lib.report.svg._legend_box(corner: str, area: tuple[float, float, float, float], rows: int, longest: int) tuple[float, float, float, float]
Return the box
(x0, y0, x1, y1)a legend of rows entries takes in corner.- Parameters:
corner (str)
area (tuple[float, float, float, float])
rows (int)
longest (int)
- Return type:
tuple[float, float, float, float]
- plesty.lib.report.svg._legend_corner(drawables: Sequence[plesty.lib.monitor.plots.Drawable]) str
Choose the corner where the legend covers the fewest trace points.
A legend fixed top-right sat on every series that rises to the right — in a log–log power dependence, on the ends of all six lines and their fits. A line is sampled along its segments, not only at its points, so a sparse line crossing a corner counts too. The top-left corner holds the scalars and text marks, so a figure with any never puts its legend there. The LaTeX renderer asks the same question, so both outputs agree.
- Parameters:
drawables (Sequence[plesty.lib.monitor.plots.Drawable]) – The figure’s drawables, as
figure_svg()receives them.- Returns:
One of
_CORNERS.- Return type:
str
- plesty.lib.report.svg._legend(traces: Sequence[Trace], area: tuple[float, float, float, float], theme: plesty.lib.ui.theme.Theme, corner: str = 'top-right') str
List every labelled trace in corner of the plot.
- Parameters:
traces (Sequence[Trace])
area (tuple[float, float, float, float])
theme (plesty.lib.ui.theme.Theme)
corner (str)
- Return type:
str
- plesty.lib.report.svg._marks(marks: Sequence[plesty.lib.monitor.plots.Scalar | plesty.lib.monitor.plots.Text], area: tuple[float, float, float, float]) str
Set scalars and text marks in the top-left corner, one line each.
- Parameters:
marks (Sequence[plesty.lib.monitor.plots.Scalar | plesty.lib.monitor.plots.Text])
area (tuple[float, float, float, float])
- Return type:
str
- plesty.lib.report.svg._levels(image: plesty.lib.monitor.plots.Image) tuple[numpy.ndarray, float, float]
Return the image scaled to
[0, 1](nanwhere missing), and its range.- Parameters:
image (plesty.lib.monitor.plots.Image)
- Return type:
tuple[numpy.ndarray, float, float]
- plesty.lib.report.svg._colour(level: numpy.ndarray, stops: Sequence[str]) numpy.ndarray
Map levels in
[0, 1]onto the colour map, as RGBA bytes.- Parameters:
level (numpy.ndarray)
stops (Sequence[str])
- Return type:
numpy.ndarray
- plesty.lib.report.svg._png(rgba: numpy.ndarray) bytes
Encode an
(rows, columns, 4)byte array as a PNG.- Parameters:
rgba (numpy.ndarray)
- Return type:
bytes
- plesty.lib.report.svg._data_uri(rgba: numpy.ndarray) str
Return a PNG as a
data:URI.- Parameters:
rgba (numpy.ndarray)
- Return type:
str
- plesty.lib.report.svg._image(image: plesty.lib.monitor.plots.Image, area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float], theme: plesty.lib.ui.theme.Theme) str
Embed the image, first row at the bottom, stretched over its extent.
- Parameters:
image (plesty.lib.monitor.plots.Image)
area (tuple[float, float, float, float])
x_range (tuple[float, float])
y_range (tuple[float, float])
theme (plesty.lib.ui.theme.Theme)
- Return type:
str
- plesty.lib.report.svg._colour_bar(image: plesty.lib.monitor.plots.Image, area: tuple[float, float, float, float], theme: plesty.lib.ui.theme.Theme) str
Draw the colour map beside the plot, labelled with the image’s range.
- Parameters:
image (plesty.lib.monitor.plots.Image)
area (tuple[float, float, float, float])
theme (plesty.lib.ui.theme.Theme)
- Return type:
str