Get help from the marimo community

Updated 6 months ago

dataframe corresponding to brushed segment of a plotly scatterplot

At a glance

A community member asks how to return a dataframe corresponding to a brushed segment of a Plotly scatterplot, similar to Altair's functionality.

Another community member suggests a solution using plotly.express, marimo, and either Polars or Pandas. They provide example code that creates a scatter plot using the cars dataset, wraps it in a Marimo UI component, and converts the plot value to a dataframe.

This is more of a python question, but is there a way to return dataframe corresponding to brushed segment of a plotly scatterplot? Similar to altair.
  • @Mustjaab
M
1 comment
@Mustjaab , you should be able to do something like

Plain Text
import plotly.express as px
import marimo as mo
from vega_datasets import data
import polars as pl # or pandas

_plot = px.scatter(
    data.cars(), x="Horsepower", y="Miles_per_Gallon", color="Origin"
)
plot = mo.ui.plotly(_plot)

# in another cell
df = pl.DataFrame(plot.value)
df
Add a reply
Sign up and join the conversation on Discord