Supported notebook environments
mainBecause drawdata is built on top of anywidget, the drawing widgets are compatible with several notebook environments, including:
- marimo
- Jupyter
- VSCode
- Colab
It can also interact with ipywidgets natively.
repository·main·Indexed 23 days ago
https://github.com/koaning/drawdataA Python library providing interactive widgets for drawing datasets directly within notebooks such as Jupyter, marimo, VSCode, and Colab. It includes ScatterWidget and BarWidget to manually create training data for machine learning, with support for exporting data as lists of dictionaries, Pandas DataFrames, Polars DataFrames, or X and y formats compatible with scikit-learn.
Because drawdata is built on top of anywidget, the drawing widgets are compatible with several notebook environments, including:
It can also interact with ipywidgets natively.
Install the drawdata library using uv pip to enable interactive data drawing widgets in your Python notebooks.
uv pip install drawdataTo start drawing a dataset immediately in a notebook, import and instantiate the ScatterWidget. Displaying the widget object in a cell will render the interactive drawing interface.
from drawdata import ScatterWidget
widget = ScatterWidget()
widgetOnce you have finished drawing data using a widget, you can access the resulting dataset through several properties depending on your preferred data structure:
widget.data: Returns the data as a list of dictionaries.widget.data_as_pandas: Returns the data as a Pandas DataFrame.widget.data_as_polars: Returns the data as a Polars DataFrame.# Get the drawn data as a list of dictionaries
widget.data
# Get the drawn data as a dataframe
widget.data_as_pandas
widget.data_as_polarsThe widget.data_as_X_y property provides data pre-formatted for machine learning tasks.
X will contain the features and y will contain the class labels.X will contain the features and y will contain the values from the y-axis.X, y = widget.data_as_X_yThe BarWidget is an interactive widget used to draw data for bar charts. It synchronizes data via the data traitlet.
Configurable properties:
y_min: Minimum value for the y-axis (float).y_max: Maximum value for the y-axis (float).n_bins: Number of bins (int).width: Widget width (int).height: Widget height (int).collection_names: A list of names for the data collections (list of strings).You can easily convert the raw drawn data from a ScatterWidget into structured dataframes using the following properties:
data_as_pandas: Returns a pandas.DataFrame constructed from the drawn data.data_as_polars: Returns a polars.DataFrame constructed from the drawn data.The BarWidget provides properties to convert drawn bar data into dataframes:
data_as_pandas: Returns a pandas.DataFrame.data_as_polars: Returns a polars.DataFrame.The data_as_X_y property of ScatterWidget extracts the drawn points into a format suitable for machine learning tasks.
X (a 2D array of x coordinates) and y (a 1D array of y coordinates).X (a 2D array of [x, y] coordinates) and colors (a list of the color values assigned to each point).The ScatterWidget is an interactive widget used to draw data points on a scatter plot. It synchronizes drawn data back to Python via the data traitlet. You can configure the visual properties like brushsize, width, height, and the number of classes (n_classes).
Constraints:
n_classes must be an integer between 1 and 4.