Plotting#
marimo supports most major plotting libraries, including Matplotlib, Seaborn, Plotly, and Altair. Just import your plotting library of choice and use it as you normally would.
For more information about plotting, see the plotting guide.
Reactive charts#
- marimo.ui.altair_chart(chart: altair.Chart, chart_selection: Literal['point'] | Literal['interval'] | bool = True, legend_selection: list[str] | bool = True, *, label: str = '', on_change: Callable[[pd.DataFrame], None] | None = None) None#
Make reactive charts with Altair
Use
mo.ui.altair_chartto make Altair charts reactive: select chart data with your cursor on the frontend, get them as a Pandas dataframe in Python!Example.
import altair as alt import marimo as mo from vega_datasets import data chart = alt.Chart(data.cars()).mark_point().encode( x='Horsepower', y='Miles_per_Gallon', color='Origin', ) chart = mo.ui.altair_chart(chart)
# View the chart and selected data as a dataframe mo.hstack([chart, chart.value])
Attributes.
value: a Pandas dataframe of the plot data filtered by the selectionsdataframe: a Pandas dataframe of the unfiltered chart dataselections: the selection of the chart; this may be an interval along the name of an axis or a selection of points
Initialization Args.
chart: Analtair.Chartchart_selection: optional selection type,"point","interval", or a bool; defaults toTruewhich will automatically detect the best selection typelegend_selection: optional list of legend fields (columns) for which to enable selecton,Trueto enable selection for all fields, orFalseto disable selection entirelylabel: optional text label for the elementon_change: optional callback to run when this element’s value changes
matplotlib#
- marimo.mpl.interactive(figure: Figure | Axes) Html#
Render a matplotlib figure using an interactive viewer.
The interactive viewer allows you to pan, zoom, and see plot coordinates on mouse hover.
Example:
plt.plot([1, 2]) # plt.gcf() gets the current figure mo.mpl.interactive(plt.gcf())
Args:
figure: a matplotlib
FigureorAxesobject
Returns:
An interactive matplotlib figure as an
Htmlobject