When to Use
- Confidence intervals: Show 95% CI around a regression line
- Prediction bands: Display forecast uncertainty
- IQR envelopes: Visualize quartile ranges in time series
- Error bars: Show measurement uncertainty along a curve
- Range visualization: Display min/max bounds for grouped data
Basic Example
Usage Modes
Standalone Mode
Create withBandPlot::new and add as Plot::Band. Pair with a Plot::Line or Plot::Scatter in the same plots vector to draw the band behind the data series.
Attached Mode
UseLinePlot::with_band or ScatterPlot::with_band as a one-call shorthand. The band inherits the series color automatically.
Key Methods
BandPlot::new(x, y_lower, y_upper)
Create a band from parallel x, lower-bound, and upper-bound iterables. All three must have the same length.
"steelblue" at opacity 0.2.
with_color(color: impl Into<String>)
Set the fill color (default "steelblue"). Accepts any CSS color string.
with_opacity(opacity: f64)
Set the fill opacity in [0.0, 1.0] (default 0.2). Lower values make the band more transparent.
with_legend(label: impl Into<String>)
Enable a legend entry with a filled rectangle swatch.
Examples
Attached to Line
.with_band() creates a band using the line’s own x positions and inherits the color automatically.
Attached to Scatter
LinePlot::with_band: band inherits scatter color and is drawn behind points.
Multiple Series with Bands
See Also
- LinePlot — For line series that can carry bands
- ScatterPlot — For scatter plots with uncertainty bands
- StackedAreaPlot — For stacked cumulative bands