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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
example: Add plotly image selection examples (#413)
Myles Scolnickd72d39bae523
diff --git a/examples/third_party/plotly_image_selection.py b/examples/third_party/plotly_image_selection.pynew file mode 100644index 0000000000..3ccf00e643--- /dev/null+++ b/examples/third_party/plotly_image_selection.py@@ -0,0 +1,110 @@+import marimo++__generated_with = "0.1.60"+app = marimo.App(width="full")+++def __():+ import marimo as mo+ import plotly.graph_objects as go+ import plotly.express as px+ from skimage import io+ return go, io, mo, px+++def __(mo):+ mo.md(+ f"""+ Required dependencies: `pip install plotly scikit-image`+ """+ )+ return+++def __(mo):+ mo.md("#Example: Image with range selection")+ return+++def __(io, mo, px):+ # Create figure+ img = io.imread("https://marimo.io/logo.png")+ _fig = px.imshow(img)+ _fig.update_layout(template="plotly_white")++ # Wrap with marimo+ plot = mo.ui.plotly(_fig)+ return img, plot+++def __(mo, plot):+ mo.hstack(+ [+ plot,+ {+ "plot.ranges": plot.ranges,+ "plot.value": plot.value,+ "plot.indcides": plot.indices,+ },+ ]+ )+ return+++def __(mo):+ mo.md("#Example: Image with overlayed trace")+ return+++def __(go, mo):+ # Create figure+ _fig = go.Figure()++ # Add trace+ _fig.add_trace(go.Scatter(x=[0, 0.5, 1, 2, 2.2], y=[1.23, 2.5, 0.42, 3, 1]))++ # Add images+ _fig.add_layout_image(+ dict(+ source="https://marimo.io/logo.png",+ xref="x",+ yref="y",+ x=0,+ y=3,+ sizex=2,+ sizey=2,+ opacity=0.8,+ layer="below",+ )+ )++ # Set templates+ _fig.update_layout(template="plotly_white")+ plot2 = mo.ui.plotly(_fig)+ return plot2,+++def __(mo, plot2):+ mo.hstack(+ [+ plot2,+ {+ "plot.ranges": plot2.ranges,+ "plot.value": plot2.value,+ "plot.indcides": plot2.indices,+ },+ ]+ )+ return+++if __name__ == "__main__":+ app.run()