1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/// A shaded area between two y-curves over a shared x-axis — typically used
/// to display confidence intervals, prediction bands, or IQR envelopes.
///
/// # Usage modes
///
/// **Standalone** — create with `BandPlot::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** — use [`LinePlot::with_band`](crate::plot::LinePlot::with_band)
/// or [`ScatterPlot::with_band`](crate::plot::ScatterPlot::with_band) as a
/// one-call shorthand. The band inherits the series color automatically and is
/// rendered behind the line or points.
///
/// # Example
///
/// ```rust,no_run
/// use kuva::plot::{BandPlot, LinePlot};
/// use kuva::backend::svg::SvgBackend;
/// use kuva::render::render::render_multiple;
/// use kuva::render::layout::Layout;
/// use kuva::render::plots::Plot;
///
/// let x: Vec<f64> = (0..50).map(|i| i as f64 * 0.2).collect();
/// let y: Vec<f64> = x.iter().map(|&v| v.sin()).collect();
/// let lower: Vec<f64> = y.iter().map(|&v| v - 0.3).collect();
/// let upper: Vec<f64> = y.iter().map(|&v| v + 0.3).collect();
///
/// let band = BandPlot::new(x.clone(), lower, upper)
/// .with_color("steelblue")
/// .with_opacity(0.25);
///
/// let line = LinePlot::new()
/// .with_data(x.iter().copied().zip(y.iter().copied()))
/// .with_color("steelblue");
///
/// let plots = vec![Plot::Band(band), Plot::Line(line)];
/// let layout = Layout::auto_from_plots(&plots)
/// .with_title("Confidence Band")
/// .with_x_label("x")
/// .with_y_label("y");
///
/// let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
/// std::fs::write("band.svg", svg).unwrap();
/// ```