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,
theme: PlotTheme | 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
|
theme
|
PlotTheme or None
|
Theme for this call, on any backend; |
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).
A registered metric is listed too, with an empty level list: a metric is
level-less, so plot_result(result, "amihud") takes no level=.
display_result ¶
Return result with prices and sizes converted to display units.
Canonical prices are integer ticks (:mod:ob_analytics.schemas); the plots
show the quote currency, so this converts each price column to the
ticks * tick_size float the faces render, reading tick_size from
result.config. :func:build_gallery_model calls it once so every face —
the prepare helpers, order_book / queue_positions called inside
them, the axes — works in display units; call it yourself before the
low-level prepare.* builders when you plot straight from a result.
Sizes are converted the same way, from integer lots to the base-asset
lots * lot_size float.
Idempotent and legacy-safe: only integer columns are scaled, so a result whose prices or sizes are already floats (a pre-tick or pre-lot file, or a result already passed through here) is returned unchanged.
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 bar, flow-toxicity, transaction-cost and LOBSTER panels and
append them to model.analytics before rendering:
model = build_gallery_model(result)
model.analytics.append(vpin_panel(vpin_df))
generate_gallery(result, "out/gallery", model=model)
bars_panel ¶
Build a bars analytic panel for :attr:GalleryModel.analytics.
bars_df is a table from :func:ob_analytics.bars.bars. label names
the rule and threshold it was cut with and is shown in the chart title;
the default reads them off the frame. Prices are drawn as they arrive, so
cut the bars from a display-unit trades frame (see :func:display_result)
when the rest of the gallery is in the quote currency.
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).
transaction_costs_panel ¶
Build a transaction-cost panel: effective and realized spread, and impact.
costs is a :func:~ob_analytics.cost.transaction_costs frame; window
is the span the per-trade costs are volume-weighted onto for the lines.
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.