Gallery¶
HTML gallery generation from pipeline results, plus the one-line
plot_result entry point for
rendering a single concept straight from a PipelineResult.
The gallery is assembled from a
GalleryModel of
PlotConcept entries built by
build_gallery_model;
generate_gallery renders
it to a self-contained HTML page.
One-line plotting¶
plot_result ¶
plot_result(
result: PipelineResult,
concept: str,
level: Level | str | None = None,
*,
backend: str = "matplotlib",
volume_scale: float | None = None,
**overrides: Any,
) -> Any
Render one plot concept straight from a :class:PipelineResult.
The one-liner the gallery is built on, without the gallery: it derives the
same per-face context (spread, focus window, snapshot, volume scale) via
:func:build_gallery_model -- the single source of truth for how each
concept binds to its prepare function -- then prepares and renders the face.
So plot_result(result, "depth_heatmap") replaces having to know the
private prepare_price_levels_data name and its argument shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
PipelineResult
|
Pipeline output ( |
required |
concept
|
str
|
Concept key, e.g. |
required |
level
|
Level or str or None
|
|
None
|
backend
|
str
|
|
'matplotlib'
|
volume_scale
|
float or None
|
Display volume scale; |
None
|
**overrides
|
Any
|
Extra keyword arguments merged over the prepare call (e.g.
|
{}
|
Returns:
| Type | Description |
|---|---|
A Matplotlib ``Figure`` or a Plotly ``Figure``, per *backend*.
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If concept is not built for this result, or has no variant at level. The message lists what is available. |
available_concepts ¶
Concept keys built for result, mapped to their available level names.
A discoverability companion to :func:plot_result: shows what
plot_result(result, concept, level=...) can render for this dataset
(which varies by format -- e.g. hidden_executions is LOBSTER-only).
Gallery model¶
build_gallery_model ¶
build_gallery_model(
result: PipelineResult,
*,
volume_scale: float | None = None,
) -> GalleryModel
Build the default gallery model from pipeline results.
Every order-book concept is registered with its Level.L2 variant (the
L3 faces are added by later renderers; a concept becomes
:attr:~PlotConcept.comparable automatically once both exist). Analytics
are not derived here -- callers append computed analytic panels (built
with the *_panel helpers) to :attr:GalleryModel.analytics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
PipelineResult
|
Pipeline output. |
required |
volume_scale
|
float or None
|
Volume display scale. |
None
|
Returns:
| Type | Description |
|---|---|
GalleryModel
|
|
GalleryModel
dataclass
¶
The gallery's inventory: leveled concepts + level-less analytics.
PlotConcept
dataclass
¶
A level-neutral plot identity with up to one variant per :class:Level.
The key never carries a level; the level lives in the registry
coordinate (concept, level, backend) and in the keys of variants.
comparable
property
¶
True when both an L2 and an L3 face are registered.
Derived, never curated: the existence of both variants is the L2<->L3 pairing, so it can never drift out of sync with what is built.
PlotSpec
dataclass
¶
PlotSpec(
name: str,
title: str,
plot_name: str,
prepare: Callable[..., dict],
prep_kwargs: dict[str, Any] = dict(),
)
How to prepare and label a single plot face.
A spec carries no level of its own -- the level is a coordinate on the
owning :class:PlotConcept (for leveled concepts) or None (for the
level-less analytics in :attr:GalleryModel.analytics).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identifier / file stem for analytic panels (e.g. |
required |
title
|
str
|
Human-readable title (used directly for analytic cards; concept cards take their title from the concept). |
required |
plot_name
|
str
|
Dispatcher concept key for :func: |
required |
prepare
|
Callable
|
|
required |
prep_kwargs
|
dict
|
Keyword arguments passed to prepare. |
dict()
|
generate_gallery ¶
generate_gallery(
result: PipelineResult | None,
output_dir: str | Path,
*,
model: GalleryModel | None = None,
view: str = "both",
volume_scale: float | None = None,
backends: list[str] | None = None,
title: str = "ob-analytics Plot Gallery",
) -> Path
Render a gallery view and write a standalone HTML page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
PipelineResult or None
|
Pipeline output. May be |
required |
output_dir
|
str or Path
|
Root directory for gallery output. |
required |
model
|
GalleryModel
|
Inventory to render. Defaults to :func: |
None
|
view
|
str
|
One of |
'both'
|
volume_scale
|
float or None
|
Volume display scale, forwarded to :func: |
None
|
backends
|
list of str
|
Backends to render. Defaults to |
None
|
title
|
str
|
Gallery page title. |
'ob-analytics Plot Gallery'
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated HTML gallery file. |
Extra panels¶
Build optional flow-toxicity and LOBSTER panels and append them via
generate_gallery(..., extra_panels=[...]).
vpin_panel ¶
Build a VPIN analytic panel for :attr:GalleryModel.analytics.
ofi_panel ¶
Build an order-flow-imbalance analytic panel.
ofi_horizon_panel ¶
ofi_horizon_panel(
trades: DataFrame,
*,
horizons: tuple[str, ...] = (
"5s",
"15s",
"60s",
"300s",
),
grid: str = "5s",
start_time: Timestamp | None = None,
end_time: Timestamp | None = None,
) -> PlotSpec
Build an OFI-vs-horizon analytic panel (diverging band per horizon).
trading_halts_panel ¶
Build a trading-halts analytic panel.
LOBSTER halts are not part of the slim :class:PipelineResult; read them
from :attr:~ob_analytics.lobster.LobsterLoader.trading_halts and pass
them here.