.md →
ScatterLog API#
Bases: AltairWidget
Accumulate (x, y[, color]) points and draw them as a live scatter.
Unlike a plain marimo state variable -- which reactivity keeps resetting --
a ScatterLog instance is stable across cell re-runs, so it can grow a
history. Create it once in its own (dependency-free) cell, then call
.append(...) from a separate reactive cell; each re-run of that cell adds
a point. Because x and y are passed explicitly they can come from
different upstream widgets.
It subclasses :class:AltairWidget, so appends update the chart in place via
the Vega changeset API (no flicker, zoom/pan preserved). Read the accumulated
points back with .data.
Examples:
import marimo as mo
from wigglystuff import ScatterLog
log = ScatterLog(x_label="energy", y_label="p(win)")
mo.ui.anywidget(log) # display once
# ...in a reactive cell that depends on `slider`:
log.append(x=slider.value, y=prob, color="run-1")
Create a ScatterLog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_label
|
str
|
Axis title for the x values. |
'x'
|
y_label
|
str
|
Axis title for the y values. |
'y'
|
color_label
|
str
|
Legend title used once colored points appear. |
'color'
|
max_points
|
int
|
Keep at most this many most-recent points (bounds the synced history so marimo exports stay small). |
500
|
width
|
int
|
Chart width in pixels. |
600
|
height
|
int
|
Chart height in pixels. |
400
|
**kwargs
|
Any
|
Forwarded to :class: |
{}
|
Source code in wigglystuff/scatter_log.py
append #
Log one or more points at x and redraw.
A single point (color optionally labels its series)::
log.append(x=1.0, y=2.0)
log.append(x=1.0, y=2.0, color="run-1")
Several named series at the same x -- each keyword becomes a series
whose name is its legend label::
log.append(x=step, loss=0.3, acc=0.9)
Source code in wigglystuff/scatter_log.py
Usage#
Create the widget once, display it, then append points from a separate reactive
cell. Pass y= for one series or use named keyword arguments to append several
series at the same x-coordinate.
data returns a copy of the accumulated points, clear() resets the plot, and
max_points bounds the retained history.
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
spec |
dict |
Current Vega-Lite scatter specification. |
width |
int |
Container width in pixels. |
height |
int |
Container height in pixels. |