Created
October 10, 2024 09:19
-
-
Save kolibril13/b87fe7de01b988e9eb14cbeda8816cf6 to your computer and use it in GitHub Desktop.
marimo drag'n'drop
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 = [ | |
# "marimo", | |
# "matplotlib==3.9.2", | |
# "numpy==2.1.2", | |
# ] | |
# /// | |
import marimo | |
__generated_with = "0.9.4" | |
app = marimo.App(width="medium") | |
@app.cell | |
def __(): | |
import marimo as mo | |
import numpy as np | |
import matplotlib.pyplot as plt | |
f = mo.ui.file(kind="area") | |
f | |
return f, mo, np, plt | |
@app.cell | |
def __(f, np, plt): | |
content = f.contents() | |
if content: | |
co = content.decode('utf-8') | |
xy_tuples = [(float(x), float(y)) for x, y in (line.split(',') for line in co.strip().split('\n')[1:]) if x and y] | |
x, y = zip(*xy_tuples) | |
if not content: | |
# Use dummy data if content is empty | |
x = np.linspace(0, 10, 40) | |
y = np.sin(x) | |
# Set the matplotlib style | |
plt.style.use('_mpl-gallery') | |
fig, ax = plt.subplots() | |
ax.scatter(x, y, c="#ffa726") | |
# Set figure size and axes properties | |
fig.set_size_inches(3, 3) | |
# Add grid and customize it | |
ax.grid(True, which='both', linestyle='--', linewidth=0.5) | |
ax.minorticks_on() | |
# Remove ticks | |
ax.set_xticks([]) | |
ax.set_yticks([]) | |
# Optionally, set axis visibility | |
ax.axis("on") | |
# Change the color of the border (spines) | |
for spine in ax.spines.values(): | |
spine.set_edgecolor("#ffa726") # Set the color to #ffa726 | |
spine.set_linewidth(2) | |
plt.gca() | |
return ax, co, content, fig, spine, x, xy_tuples, y | |
@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