Last active
August 7, 2024 09:49
-
-
Save kolibril13/ec06ef89e2a014f09c9284156ff9e644 to your computer and use it in GitHub Desktop.
marimo reactive tldraw colorpicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import marimo | |
__generated_with = "0.7.17" | |
app = marimo.App(width="medium") | |
@app.cell | |
def __(): | |
import matplotlib.pyplot as plt | |
import numpy as np | |
plt.style.use('_mpl-gallery') | |
np.random.seed(3) | |
x = 4 + np.random.normal(0, 2, 24) | |
y = 4 + np.random.normal(0, 2, len(x)) | |
sizes = np.random.uniform(15, 80, len(x)) | |
opacity = np.random.uniform(0, 1, len(x)) | |
return np, opacity, plt, sizes, x, y | |
@app.cell | |
def __(): | |
import marimo as mo | |
return mo, | |
@app.cell | |
def __(mo): | |
from tldraw import ReactiveColorPicker | |
widget = mo.ui.anywidget(ReactiveColorPicker()) | |
widget | |
return ReactiveColorPicker, widget | |
@app.cell | |
def __(np, opacity, plt, sizes, widget, x, y): | |
fig, ax = plt.subplots() | |
ax.scatter(x, y, s=sizes*5, color=widget.color or None, alpha=opacity) | |
fig.set_size_inches(3, 3) | |
ax.set(xlim=(0, 8), xticks=np.arange(1, 8), ylim=(0, 8), yticks=np.arange(1, 8)) | |
plt.gca() | |
return ax, fig | |
@app.cell | |
def __(): | |
return | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment