Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/marimo-team/marimo/llms.txt

Use this file to discover all available pages before exploring further.

The data explorer provides an interactive way to quickly visualize and understand your datasets with automatically generated charts.

Overview

mo.ui.data_explorer() creates an interactive visualization tool that:
  • Suggests appropriate chart types based on your data
  • Allows drag-and-drop encoding of visual channels
  • Updates visualizations in real-time
  • Works with pandas, polars, and other dataframe libraries

Basic Usage

import marimo as mo
import pandas as pd

df = pd.DataFrame({
    "category": ["A", "B", "C", "A", "B"],
    "value": [10, 20, 15, 25, 30],
    "date": pd.date_range("2024-01-01", periods=5),
    "size": [100, 200, 150, 175, 225]
})

explorer = mo.ui.data_explorer(df)
explorer
The data explorer appears with:
  • Chart type selector (bar, line, scatter, etc.)
  • Encoding channels (x, y, color, size, etc.)
  • Interactive preview

Pre-configured Charts

Start with specific encodings:
import marimo as mo
import pandas as pd

df = pd.DataFrame({
    "month": ["Jan", "Feb", "Mar", "Apr"],
    "revenue": [100, 150, 120, 180],
    "expenses": [80, 90, 85, 95],
    "region": ["North", "North", "South", "South"]
})

# Start with a pre-configured chart
explorer = mo.ui.data_explorer(
    df,
    x="month",
    y="revenue",
    color="region"
)

Available Encodings

The data explorer supports multiple visual encodings:

Position

  • x - X-axis position
  • y - Y-axis position
  • row - Facet by row
  • column - Facet by column

Marks

  • color - Color encoding
  • size - Size of marks
  • shape - Shape of points

Example: Multi-dimensional Visualization

import marimo as mo
import pandas as pd

df = pd.DataFrame({
    "x_val": range(20),
    "y_val": [i**2 for i in range(20)],
    "category": ["A", "B"] * 10,
    "size_val": [i*10 for i in range(20)],
    "shape_val": ["circle", "square", "triangle"] * 6 + ["circle", "square"]
})

explorer = mo.ui.data_explorer(
    df,
    x="x_val",
    y="y_val",
    color="category",
    size="size_val",
    shape="shape_val"
)

Accessing the Chart Specification

Retrieve the chart configuration:
import marimo as mo

df = pd.DataFrame({
    "x": [1, 2, 3],
    "y": [4, 5, 6]
})

explorer = mo.ui.data_explorer(df, x="x", y="y")
In another cell:
# Get the current encoding
encoding = explorer.value

mo.md(f"""
## Current Chart Configuration

- X-axis: {encoding.get('x', 'None')}
- Y-axis: {encoding.get('y', 'None')}
- Color: {encoding.get('color', 'None')}
""")

Supported Data Types

The data explorer works with any dataframe library supported by narwhals:
import pandas as pd
import marimo as mo

df = pd.DataFrame({
    "a": [1, 2, 3],
    "b": [4, 5, 6]
})

mo.ui.data_explorer(df)

Chart Types

The data explorer automatically suggests appropriate chart types based on your data and selected encodings:
  • Bar charts - For categorical comparisons
  • Line charts - For temporal data
  • Scatter plots - For correlations
  • Histograms - For distributions
  • Box plots - For statistical summaries
  • Heatmaps - For matrix data
Users can override the suggested type using the chart type selector in the UI.

Interactive Features

1
Drag and Drop
2
Drag column names from the data panel to encoding channels (x, y, color, etc.)
3
Change Chart Type
4
Click the chart type selector to switch between visualization types.
5
Adjust Encodings
6
Click on encoding channels to change:
7
  • Aggregation functions (sum, mean, count, etc.)
  • Data type interpretation (quantitative, temporal, nominal)
  • Binning for continuous variables
  • 8
    Download Chart
    9
    Export visualizations as PNG or SVG.

    Reactive Updates

    The data explorer is reactive - when the input dataframe changes, the visualization automatically updates:
    import marimo as mo
    import pandas as pd
    
    # Slider to filter data
    max_value = mo.ui.slider(10, 100, value=50, label="Max Value")
    
    In another cell:
    # Filtered data
    df_filtered = df[df["value"] <= max_value.value]
    
    # Explorer updates when slider changes
    mo.ui.data_explorer(df_filtered, x="category", y="value")
    

    Combining with Other UI Elements

    Create dashboards by combining the data explorer with other components:
    import marimo as mo
    import pandas as pd
    
    df = pd.DataFrame({
        "product": ["A", "B", "C", "D"],
        "sales": [100, 200, 150, 300],
        "region": ["North", "South", "North", "South"]
    })
    
    # Region selector
    region = mo.ui.dropdown(
        options=["All", "North", "South"],
        value="All",
        label="Region"
    )
    
    In another cell:
    # Filter data based on selection
    df_filtered = df if region.value == "All" else df[df["region"] == region.value]
    
    # Display region selector and explorer
    mo.vstack([
        region,
        mo.ui.data_explorer(df_filtered, x="product", y="sales")
    ])
    

    Performance Considerations

    For large datasets (100k+ rows), the data explorer uses sampling to maintain interactivity.
    • Data is automatically sampled for preview
    • Full dataset is used for aggregations
    • Consider pre-aggregating very large datasets

    Under the Hood

    The data explorer uses:
    • Vega-Lite for declarative visualizations
    • Altair (via marimo’s chart transformer) for efficient rendering
    • CSV data transformation for browser compatibility

    Example: Sales Dashboard

    import marimo as mo
    import pandas as pd
    import numpy as np
    
    # Generate sample sales data
    np.random.seed(42)
    dates = pd.date_range("2024-01-01", periods=100)
    df = pd.DataFrame({
        "date": dates,
        "revenue": np.random.randint(1000, 5000, 100),
        "customers": np.random.randint(10, 100, 100),
        "product": np.random.choice(["Widget", "Gadget", "Tool"], 100),
        "region": np.random.choice(["North", "South", "East", "West"], 100)
    })
    
    # Interactive explorer
    explorer = mo.ui.data_explorer(
        df,
        x="date",
        y="revenue",
        color="product"
    )
    
    explorer
    
    Users can now:
    • Switch to different chart types
    • Add faceting by region
    • Change aggregation methods
    • Explore temporal patterns
    All without writing any visualization code!

    Comparison with Other Tools

    FeatureData ExplorerAltair ChartPlotly
    No code required
    Automatic suggestions
    Drag-and-drop
    Full customizationLimited
    Export code
    Use the data explorer for quick exploration, then switch to mo.ui.altair_chart() or mo.ui.plotly() for production visualizations.

    Tips

    Fast Exploration: Use the data explorer when you first receive a dataset to understand its structure and relationships.
    Prototyping: Quickly prototype visualizations before writing custom chart code.
    Presentations: Great for interactive demos where the audience can explore data live.

    Limitations

    • Chart customization is limited compared to programmatic approaches
    • Complex visualizations may require mo.ui.altair_chart() or mo.ui.plotly()
    • No direct access to underlying Vega-Lite specification for modification
    For advanced use cases, consider combining the data explorer for initial exploration with custom charts for final presentation.

    Build docs developers (and LLMs) love