Skip to main content
marimo makes plots interactive and reactive. Select data in your charts, and marimo automatically updates Python with your selections.

Supported Libraries

marimo provides first-class support for three major plotting libraries:
  • Altair - Declarative visualization library based on Vega-Lite
  • Plotly - Interactive graphing library
  • Matplotlib - Publication-quality static plots with selection overlay

Altair Charts

Basic Usage

Accessing Selected Data

Selection Types

Drag to select a rectangular region.

Custom Selections

If your chart already has selection parameters, marimo respects them:

Layered Charts

For layered or concatenated charts, use apply_selection():
In another cell:

Chart Composition

marimo’s Altair charts support composition operators:

Plotly Charts

Basic Usage

Selection Data

Plotly selections provide multiple data views:

Supported Chart Types

Scatter & Line

  • scatter
  • scattergl (WebGL)
  • Line charts
  • Area charts

Statistical

  • Bar charts
  • Histograms
  • Box plots
  • Violin plots

Hierarchical

  • Treemap
  • Sunburst
  • Icicle

Specialized

  • Heatmaps
  • Contour plots
  • Geographic maps

Configuration

See Plotly configuration options for all available settings.

Map Selections

Plotly map traces (scattergeo, scattermapbox) support selection:
Selections include lat/lon coordinates:

Matplotlib Plots

Interactive Selections

marimo adds interactive selection to static matplotlib plots:

Selection Types

1

Box Selection

Click and drag to select a rectangular region.
2

Lasso Selection

Hold Shift and drag to draw a freehand selection.

Using Selection Masks

Selection Objects

The value attribute returns different selection types:

Debouncing

Control when selections are sent to Python:

Reactive Visualizations

Combine charts with other UI elements for dashboards:
Whenever min_hp changes, the chart automatically updates.

Performance Tips

For large datasets, consider these optimizations:
  • Altair: Use mark_point() with size encoding instead of large markers
  • Plotly: Use scattergl instead of scatter for 10k+ points
  • Matplotlib: Selections are computed in JavaScript, so they remain fast
  • Data transformers: Altair supports vegafusion for server-side processing

VegaFusion

For very large Altair datasets:
marimo automatically detects vegafusion and adjusts chart rendering accordingly.

Theming

Charts respect marimo’s dark/light mode:
  • Altair: Backgrounds are automatically transparent
  • Plotly: Uses the configured renderer theme
  • Matplotlib: Renders with current style settings

Best Practices

  1. Keep charts reactive - Store chart objects in variables and reference UI values
  2. Use appropriate selection types - Point selection for discrete data, interval for continuous
  3. Handle empty selections - Check if data is selected before processing
  4. Combine with dataframes - Use mo.ui.dataframe() to show selected data in tabular form
  5. Optimize for size - Sample or aggregate data before plotting millions of points

Example: Interactive Dashboard

This creates a fully reactive dashboard where selecting points updates the table automatically.