Plotting
Part 5 of 10 in Learn marimo.
marimo supports several popular plotting libraries, including matplotlib, plotly, seaborn, and altair.
This tutorial gives examples using matplotlib; other libraries are used similarly.
Matplotlib
Section titled “Matplotlib”To show a plot, include it in the last expression of a cell (just like any other output).
# create the plot in the last line of the cellimport matplotlib.pyplot as pltplt.plot([1, 2])# create a plotplt.plot([1, 2])# ... do some work ...# make plt.gca() the last line of the cellplt.gca()A new figure every cell. Every cell starts with an empty figure for
the imperative pyplot API.
To build a figure over multiple cells, use the object-oriented API and create your own axis:
Draw plots interactively
Section titled “Draw plots interactively”Draw plots interactively by parametrizing them with UI elements.
Reactive selections with mo.ui.matplotlib
Section titled “Reactive selections with mo.ui.matplotlib”Wrap a matplotlib Axes in mo.ui.matplotlib to let users select
data with box selections (click-drag) or lasso selections
(shift-drag). Use fig.value.get_mask(x, y) to get a boolean mask
of the selected points.
Other libraries
Section titled “Other libraries”marimo also supports these other plotting libraries:
- Plotly
- Seaborn
- Altair
Just output their figure objects as the last expression of a cell,
or embed them in markdown with mo.as_html.
If you would like another library to be integrated into marimo, please get in touch.