Created
October 10, 2024 11:35
-
-
Save kolibril13/346de72797b2c8ed2ba5361ff7250feb to your computer and use it in GitHub Desktop.
marimo reactflow color picker with uv requirements (run with `uvx marimo edit --sandbox color_picker.py` )
This file contains hidden or 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
| # /// script | |
| # requires-python = ">=3.12" | |
| # dependencies = [ | |
| # "ipyreactflow==0.0.7", | |
| # "marimo", | |
| # "matplotlib==3.9.2", | |
| # "numpy==2.1.2", | |
| # ] | |
| # /// | |
| import marimo | |
| __generated_with = "0.8.17" | |
| app = marimo.App(width="medium") | |
| @app.cell | |
| def __(): | |
| import marimo as mo | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| plt.style.use('_mpl-gallery') | |
| np.random.seed(21) | |
| 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 mo, np, opacity, plt, sizes, x, y | |
| @app.cell | |
| def __(mo): | |
| from ipyreactflow import ColorPicker | |
| widget =mo.ui.anywidget(ColorPicker()) | |
| widget | |
| return ColorPicker, widget | |
| @app.cell | |
| def __(widget): | |
| widget.target_node | |
| return | |
| @app.cell | |
| def __(np, opacity, plt, sizes, widget, x, y): | |
| fig, ax = plt.subplots() | |
| if widget.target_node == "green": | |
| c= "limegreen" | |
| if widget.target_node == "blue": | |
| c= "deepskyblue" | |
| ax.scatter(x, y, s=sizes*30, color=c or None, alpha=opacity*1) | |
| 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, c, 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