Skip to main content
Make reactive plots with Plotly.

Usage

import plotly.express as px
import marimo as mo
from vega_datasets import data

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

plot = mo.ui.plotly(_plot)
# View the plot and selected data
mo.hstack([plot, plot.value])
Or with custom configuration:
plot = mo.ui.plotly(
    _plot,
    config={"staticPlot": True},
)

Signature

mo.ui.plotly(
    figure: plotly.graph_objects.Figure,
    config: Optional[Dict[str, Any]] = None,
    renderer_name: Optional[str] = None,
    *,
    label: str = "",
    on_change: Optional[Callable[[JSONType], None]] = None
)

Parameters

figure
plotly.graph_objects.Figure
required
A plotly Figure object.
config
Optional[Dict[str, Any]]
default:"None"
Configuration for the plot. This is a dictionary that is passed directly to plotly. See the plotly documentation for more information. This takes precedence over the default configuration of the renderer.
renderer_name
Optional[str]
default:"None"
Renderer to use for the plot. If this is not provided, the default renderer (pio.renderers.default) is used.
label
str
default:""
Markdown label for the element.
on_change
Optional[Callable[[JSONType], None]]
default:"None"
Callback to run when this element’s value changes.

Attributes

value
Dict[str, Any]
A dict of the plot data.
ranges
Dict[str, List[float]]
The selection of the plot; this may be an interval along the name of an axis.
points
List[Dict[str, Any]]
The selected points data.
indices
List[int]
The indices of selected points.

Supported Chart Types

This function supports:
  • Scatter plots
  • Scattergl plots
  • Line charts
  • Area charts
  • Bar charts
  • Treemap charts
  • Sunburst charts
  • Heatmaps

Build docs developers (and LLMs) love