Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

tldraw colorpicker example

Akshay Agrawal49c9e42fa117
diff --git a/examples/anywidget/tldraw_colorpicker.py b/examples/anywidget/tldraw_colorpicker.py
new file mode 100644
index 0000000000..c04fe96819
--- /dev/null
+++ b/examples/anywidget/tldraw_colorpicker.py
@@ -0,0 +1,43 @@
+import marimo
+
+__generated_with = "0.7.17"
+app = marimo.App(width="medium")
+
+
+def __():
+ import matplotlib.pyplot as plt
+ import numpy as np
+ plt.style.use('_mpl-gallery')
+
+ # make the data
+ np.random.seed(3)
+ x = 4 + np.random.normal(0, 2, 24)
+ y = 4 + np.random.normal(0, 2, len(x))
+ # size and color:
+ sizes = np.random.uniform(15, 80, len(x))
+ opacity = np.random.uniform(0, 1, len(x))
+ return np, opacity, plt, sizes, x, y
+
+
+def __():
+ from tldraw import ReactiveColorPicker
+ import marimo as mo
+
+ widget = mo.ui.anywidget(ReactiveColorPicker())
+ return ReactiveColorPicker, mo, widget
+
+
+def __(mo, np, opacity, plt, sizes, widget, x, y):
+ fig, ax = plt.subplots()
+ fig.set_size_inches(3, 3)
+ ax.set(xlim=(0, 8), xticks=np.arange(1, 8), ylim=(0, 8), yticks=np.arange(1, 8))
+ ax.scatter(x, y, s=sizes*5, color=widget.color or None, alpha=opacity)
+ mo.hstack([widget, plt.gca()], justify="start", widths=[1, 1])
+ return ax, fig
+
+
+if __name__ == "__main__":
+ app.run()