Interactive Plotly Express plotting for xarray
pip install xarray_plotlyimport xarray as xr
import numpy as np
import xarray_plotly # registers the accessor
da = xr.DataArray(
np.random.randn(100, 3).cumsum(axis=0),
dims=["time", "city"],
coords={"time": np.arange(100), "city": ["NYC", "LA", "Chicago"]},
)
# Accessor style
fig = da.plotly.line()
fig.show()
# Or with xpx() for IDE code completion
from xarray_plotly import xpx
fig = xpx(da).line()Why xpx()? The accessor (da.plotly) works but IDEs can't provide code completion for it. This is because xarray accessors are registered dynamically at runtime, making them invisible to static type checkers. The xpx() function provides the same functionality with full IDE support. This limitation could only be solved by xarray itself, if at all — it may be a fundamental Python limitation.
Full documentation: https://fbumann.github.io/xarray_plotly
Planned additions (contributions welcome):
New plot types
histogram()— distribution of DataArray valuesviolin()— richer distribution visualization than box plotsdensity_heatmap()— 2D histograms (x and y as dimensions)density_contour()— 2D density contours (x and y as dimensions)
Enhancements
- WebGL rendering option for
line()andscatter()(large datasets)
Figure utilities (facet/animation-aware)
fill_between()— fill area between two traces (uncertainty bands)sync_axes()— consistent axis ranges across facets and animation framesadd_secondary_x()— secondary x-axis (likeadd_secondary_y())stack()— vertically stack separate figures into subplots
MIT