Home
xarray_plotly
¶
Interactive Plotly Express plotting for xarray.
This package provides a plotly accessor for xarray DataArray and Dataset objects,
enabling interactive visualization with Plotly Express.
Features
- Interactive plots: Zoom, pan, hover, toggle traces
- Automatic dimension assignment: Dimensions fill slots (x, color, facet) by position
- Multiple plot types: line, bar, area, scatter, box, imshow
- Dataset support: Plot all variables at once with "variable" dimension
- Faceting and animation: Built-in subplot grids and animated plots
- Customizable: Returns Plotly Figure objects for further modification
Usage
Accessor style::
import xarray_plotly
fig = da.plotly.line()
fig = ds.plotly.line() # Dataset: all variables
Function style (recommended for IDE completion)::
from xarray_plotly import xpx
fig = xpx(da).line()
fig = xpx(ds).line() # Dataset: all variables
Example
import xarray as xr
import numpy as np
from xarray_plotly import xpx
da = xr.DataArray(
np.random.rand(10, 3, 2),
dims=["time", "city", "scenario"],
)
fig = xpx(da).line() # Auto: time->x, city->color, scenario->facet_col
fig = xpx(da).line(x="time", color="scenario") # Explicit
fig = xpx(da).line(color=None) # Skip slot
# Dataset: plot all variables (accessor or xpx)
ds = xr.Dataset({"temp": da, "precip": da})
fig = xpx(ds).line() # "variable" dimension for color
fig = xpx(ds).line(facet_col="variable") # Facet by variable
Next Steps¶
- Getting Started - Interactive tutorial
- Plot Types - All available plot types
- Dimensions & Facets - Control dimension mapping
- Figure Customization - Customize your figures
- API Reference - Full API documentation