plesty.lib.ui.qt.plot

pyqtgraph renderer: draws a monitor’s declared traces into a Qt widget.

This is the only place in the platform that knows both a Monitor and a plotting library. The monitor declares what it draws (TraceSpec) and hands over what to draw (TraceData); this module turns that into plot items and keeps them fed. pyqtgraph is used because a trace fed every few hundred milliseconds for hours must redraw without the operator noticing.

Colours never appear here as literals: every pen comes from the Theme, which reads the packaged palette.

Classes

PlotRenderer

Draw target that renders a monitor's traces into a pyqtgraph widget.

Functions

_colormap(→ pyqtgraph.ColorMap)

Build the image colour map from the theme's colour-map stops.

_levels(→ tuple[float, float])

Return the colour range to draw array over.

_sqrt_ticks(→ list[tuple[float, str]])

Return colour-bar ticks for a square-root scale from base to top.

Module Contents

plesty.lib.ui.qt.plot._colormap(theme: plesty.lib.ui.theme.Theme) → pyqtgraph.ColorMap

Build the image colour map from the theme’s colour-map stops.

The map itself is returned rather than a lookup table, because the colour bar beside an image has to be drawn from the same one: a legend built from a second map would be a legend for a different picture.

Parameters:

theme (plesty.lib.ui.theme.Theme)

Return type:

pyqtgraph.ColorMap

plesty.lib.ui.qt.plot._levels(array: numpy.ndarray) → tuple[float, float]

Return the colour range to draw array over.

The top of the range is the brightest value that its neighbouring rows confirm — the maximum of the image after a median over each three consecutive rows — not the brightest pixel. The rows of a map are its sweep positions (a waterfall stacks one spectrum per row), so an emission line runs through many rows while a cosmic ray hits one. From the brightest pixel, one cosmic ray of forty thousand counts sets the top and every weak line is drawn in the colour of the background; this way, cosmic rays saturate and the lines use the colours. A map of fewer than three rows has nothing to confirm against and uses its brightest value.

A waterfall pads a ragged row with NaN and a map may arrive before any row has, so neither the empty case nor the all-NaN one is unusual enough to raise on.

Parameters:

array (numpy.ndarray) – The image.

Returns:

Low and high level, always with high > low — a zero-width range gives a bar no scale to draw and a map no contrast.

Return type:

tuple[float, float]

plesty.lib.ui.qt.plot._sqrt_ticks(base: float, top: float) → list[tuple[float, str]]

Return colour-bar ticks for a square-root scale from base to top.

The scale places a value v at √(v − base). The ticks are round numbers in the image’s own units, placed there, so the bar reads in counts although the colours follow the square root.

Parameters:
  • base (float) – The value at the bottom of the scale (the background).

  • top (float) – The value at the top of the scale.

Return type:

list[tuple[float, str]]

class plesty.lib.ui.qt.plot.PlotRenderer(theme: plesty.lib.ui.theme.Theme | None = None, parent: PySide6.QtWidgets.QWidget | None = None)

Bases: plesty.lib.monitor.base_monitor.Renderer

Draw target that renders a monitor’s traces into a pyqtgraph widget.

The renderer owns its widget (widget), so a panel builds one and hands the widget to the shell:

renderer = PlotRenderer(theme)
monitor.attach(renderer)      # builds the plot items, replays the last data
shell_panel_widget = renderer.widget

Create the plot widget.

Parameters:
  • theme (Optional[plesty.lib.ui.theme.Theme]) – Palette to resolve trace colours and chrome against; None loads the packaged PLESTY theme.

  • parent (Optional[PySide6.QtWidgets.QWidget]) – Parent widget.

theme
widget
plot
caption
_layout
_items: dict[str, Any]
_images: dict[str, pyqtgraph.ImageItem]
_colorbars: dict[str, pyqtgraph.ColorBarItem]
_texts: dict[str, tuple[str, str]]
_names: dict[str, str]
_named: list[str] = []
_colormap
_lut
setup(monitor: plesty.lib.monitor.base_monitor.Monitor) → None

Build one plot item per declared trace.

Parameters:

monitor (plesty.lib.monitor.base_monitor.Monitor) – The monitor that was attached.

Return type:

None

draw(monitor: plesty.lib.monitor.base_monitor.Monitor, data: dict[str, plesty.lib.monitor.base_monitor.TraceData]) → None

Feed new payloads into the plot items.

Parameters:
Return type:

None

clear(monitor: plesty.lib.monitor.base_monitor.Monitor) → None

Empty every plot item without rebuilding them.

Parameters:

monitor (plesty.lib.monitor.base_monitor.Monitor) – The monitor whose view is being reset.

Return type:

None

_style_plot() → None

Apply the theme to the plot background, axes, and grid.

Return type:

None

_style_colorbar(bar: pyqtgraph.ColorBarItem, label: str) → None

Apply the theme to a colour bar and name what it measures.

Parameters:
  • bar (pyqtgraph.ColorBarItem) – The bar beside an image trace.

  • label (str) – The trace’s label, which names the quantity the colours stand for.

Return type:

None

_place_legend(wanted: bool) → None

Put the legend in its own column right of the plot, or take it away.

A legend floating inside the plot covers the data it names, and a corner that is empty for one frame is full for the next. In the plot item’s layout it takes its width from the plot instead. The plot item adds every named curve to item.legend, so that is where it goes.

Parameters:

wanted (bool) – Whether the view has curves to name.

Return type:

None

_sync_legend() → None

Show a legend entry for every named curve that has data, in declaration order.

A view declares its traces once, before any data, often more than it will fill — a slot per line it might find. An entry for a curve with nothing drawn would name a line that is not there.

Return type:

None

_drop_colorbars() → None

Remove every colour bar from the plot item’s layout.

Return type:

None

_build_item(spec: plesty.lib.monitor.base_monitor.TraceSpec, index: int) → None

Create the plot item declared by one trace spec.

Parameters:
Return type:

None

_draw_curve(key: str, payload: plesty.lib.monitor.base_monitor.TraceData) → None

Update one line or scatter trace.

Parameters:
Return type:

None

_draw_image(key: str, payload: plesty.lib.monitor.base_monitor.TraceData, scale: str = 'linear') → None

Update one image trace, scaling it onto its physical axes.

Parameters:
Return type:

None

_draw_text(key: str, spec: plesty.lib.monitor.base_monitor.TraceSpec, payload: plesty.lib.monitor.base_monitor.TraceData) → None

Record a scalar or text trace for the caption under the plot.

The label is written in the trace’s colour, so a text that belongs to a curve — a fitted line’s result — reads as that curve’s. An empty text takes the entry out of the caption.

Parameters:
Return type:

None

_caption_html() → str

Return the caption: scalar readings on one line, then each text on its own line.

Return type:

str