core_lens.base.namespaces.plot#
Visualisation namespace for Results.
Classes#
Temporal dimensions to split plot data across. |
|
Wrapper around lonboard.Map that adds a legend for Jupyter and HTML exports. |
|
Visualisation namespace for |
Module Contents#
- class core_lens.base.namespaces.plot.SubplotOn(*args, **kwds)#
Bases:
enum.EnumTemporal dimensions to split plot data across.
Used to specify how data should be partitioned into subplots or map layers based on temporal columns added during materialisation.
- Variables:
YEAR – Split data by year.
MONTH – Split data by month.
SEASON – Split data by meteorological season.
SEASON_YEAR – Split data by season and year.
- YEAR = 'year'#
- MONTH = 'month'#
- SEASON = 'season'#
- SEASON_YEAR = 'season_year'#
- class core_lens.base.namespaces.plot.MapWithLegend(map_widget: Any, cmap: Any, v_min: float, v_max: float, column_name: str, clamped_min: bool = False, clamped_max: bool = False)#
Wrapper around lonboard.Map that adds a legend for Jupyter and HTML exports.
- __getattr__(name: str) Any#
Get map attribute.
- Parameters:
name – The attribute name to look up on the underlying map.
- Returns:
The requested attribute from the map widget.
- to_html(filename: str | None = None, title: str | None = None) str | None#
Export the map to a static HTML string or file, injecting the legend.
- class core_lens.base.namespaces.plot.PlotNamespace(result: core_lens.base.result.Result)#
Visualisation namespace for
Result.Methods return map or chart objects.
- Variables:
result – The parent Result object.
- result#
- choropleth(column: str, subplot_on: SubplotOn | None = None, v_min: float | None = None, v_max: float | None = None) MapWithLegend#
Render an interactive choropleth map using Lonboard.
If the Result does not already have geometry, it will be attached automatically via
with_geometry().- Parameters:
column (str) – The column to use for colour mapping.
subplot_on (SubplotOn | None, optional) – Optional temporal dimension to split data across. A
SubplotOnenum value. When set, one layer is rendered per unique value ofsubplot_onin the data.v_min (float | None, optional) – Minimum value for color scale.
v_max (float | None, optional) – Maximum value for color scale.
- Returns:
A Lonboard Map object.
- Return type:
lonboard.Map
- Raises:
ValueError – If
columnorsubplot_oncolumn not found in data.NotImplementedError – Lonboard does not support native subplot grids; only single-value
subplot_onis rendered when specified.
- Under the hood:
Calls
lonboard.Mapandlonboard.PolygonLayerto render high-performance WebGL maps.Uses
geoarrow.rust.core.from_wkbfor zero-copy geometry conversion from Polars WKB.Colormaps are applied via
lonboard.colormap.apply_continuous_cmap(using matplotlib colormaps).
- timeseries(x: str | None = None, y: str | list[str] | None = None, subplot_on: SubplotOn | str | None = None, top_n: int = 10, aggregate: bool = False) Any#
Render a timeseries line chart using Bokeh.
Returns a
bokeh.models.Tabswidget with two panels: Per Entity (up totop_nentities) and Aggregated Mean. Whenaggregate=True, only the aggregated panel is returned as a plainbokeh.plotting.figure.- Parameters:
x (str | None, optional) – The temporal column to plot on the x-axis.
y (str | list[str] | None, optional) – The value column(s) to plot on the y-axis. If
None, all numeric columns (exceptx) are used.subplot_on (SubplotOn | str | None, optional) – Optional temporal dimension to split data across. A
SubplotOnenum value or string.top_n (int, optional) – Maximum number of entities rendered in per-entity view.
aggregate (bool, optional) – If
True, renders only the aggregated mean view.
- Returns:
A Bokeh Tabs object (or a single Figure when
aggregate=True).- Return type:
Any
- Under the hood:
Uses
bokeh.plotting.figureto construct interactive line and scatter charts. Data is passed viabokeh.models.ColumnDataSourceand split into tabs usingbokeh.models.Tabs.
- scatter(x: str | None = None, y: str | list[str] | None = None, top_n: int = 10) Any#
Render a scatter plot using Bokeh.
- Parameters:
x (str | None, optional) – The column to plot on the x-axis.
y (str | list[str] | None, optional) – The column(s) to plot on the y-axis. If None, auto-selects all numeric.
top_n (int, optional) – Maximum number of entities to plot.
- Returns:
A Bokeh Figure or Tabs object.
- Return type:
Any
- Under the hood:
Uses
bokeh.plotting.figurefor the scatter plot rendering, populating data through aColumnDataSourceto enable tooltips and interactive panning.
- distribution(x: str | list[str] | None = None, top_n: int = 10) Any#
Render a distribution (histogram) plot using Bokeh.
- Parameters:
x (str | list[str] | None, optional) – The column(s) to plot the distribution for. If None, auto-selects all numeric.
top_n (int, optional) – Maximum number of entities to include.
- Returns:
A Bokeh Figure or Tabs object.
- Return type:
Any
- Under the hood:
Computes histogram bins and counts efficiently using
numpy.histogram_bin_edgesandnumpy.histogram.Renders the resulting distribution using the
quadglyph inbokeh.plotting.figure.
- correlation(columns: list[str] | None = None, top_n: int = 10) Any#
Render a correlation heatmap using Bokeh.
- Parameters:
columns (list[str] | None, optional) – Optional list of columns to correlate. Defaults to all numeric.
top_n (int, optional) – Maximum number of entities to include (currently unused).
- Returns:
A Bokeh Figure object.
- Return type:
Any
- Under the hood:
Computes the Pearson correlation matrix using pandas’ native
corr()method.Renders a heatmap grid using Bokeh’s
rectglyph andLinearColorMapper.
- heatmap(x: str | None = None, y: str | None = None, value: str | None = None, top_n: int = 10) Any#
Render a heatmap using Bokeh.
- Parameters:
x (str | None, optional) – The column for the x-axis.
y (str | None, optional) – The column for the y-axis.
value (str | None, optional) – The column for the colour values.
top_n (int, optional) – Maximum number of entities to include (currently unused).
- Returns:
A Bokeh Figure object.
- Return type:
Any
- Under the hood:
Pivots the Polars DataFrame to a 2D matrix.
Uses
bokeh.plotting.figurewithrectglyphs andLinearColorMapperfor the color scale.
- matrix() Any#
Render a scatter matrix (pairs plot) using Bokeh.
- Returns:
A Bokeh
gridplotobject.- Return type:
Any
- Under the hood:
Iterates through all pairs of numeric columns, creating a grid of individual Bokeh scatter plots and assembling them into a single layout using
bokeh.layouts.gridplot.