.md →
ScatterWidget API#
ScatterWidget is a paintable scatter canvas: pick a class color, drag the brush, and the
points you paint come back as data (or as a DataFrame via data_as_pandas). It is the
fastest way to invent a small labeled 2D dataset for testing a classifier, sanity-checking
a clustering algorithm, or drawing the pathological case you want to explain. Up to four
classes, each with its own color and label, plus a batch key per stroke.
See also: SplineDraw for the same canvas with a Python-fitted curve on top, ChartMultiSelect for labeling data you already have, and ScatterLog for accumulating computed points rather than drawn ones.
Note:
ScatterWidgetis provided by thedrawdatapackage and re-exported here for convenience. You can use it viafrom wigglystuff import ScatterWidgetorfrom drawdata import ScatterWidget.
Bases: AnyWidget
Interactive scatter drawing widget for painting multi-class 2D data points.
The widget renders a D3-powered SVG canvas where you can paint data points using a configurable brush. Points are grouped by class (color) and batch, making it easy to generate labeled 2D datasets interactively.
Examples:
import marimo as mo
from wigglystuff import ScatterWidget
widget = mo.ui.anywidget(ScatterWidget(n_classes=3))
widget
Create a ScatterWidget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_classes
|
int
|
Number of point classes (1-4). Each class gets a distinct color and label. |
4
|
brushsize
|
int
|
Initial brush radius in pixels. |
40
|
width
|
int
|
SVG viewBox width in pixels. |
800
|
height
|
int
|
SVG viewBox height in pixels. |
400
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If n_classes is not between 1 and 4. |
Source code in wigglystuff/scatter_widget.py
data_as_X_y
property
#
Return the drawn points as a (X, y) tuple of numpy arrays.
When configured with n_classes=1 (regression scenario), returns
X with shape (n, 1) containing x values and y
as the target array.
When configured with n_classes>1 (classification scenario),
returns X with shape (n, 2) containing (x, y)
coordinates and y as a list of color strings.
data_as_pandas
property
#
Return the drawn points as a :class:pandas.DataFrame.
Columns: x, y, color, label, batch.
data_as_polars
property
#
Return the drawn points as a :class:polars.DataFrame.
Columns: x, y, color, label, batch.
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
data |
list[dict] |
List of drawn points with x, y, color, label, batch keys. |
brushsize |
int |
Brush radius in pixels (default: 40). |
width |
int |
SVG viewBox width in pixels (default: 800). |
height |
int |
SVG viewBox height in pixels (default: 400). |
n_classes |
int |
Number of point classes, 1-4 (default: 4). |