pub struct FillBetween { /* private fields */ }Expand description
Fills the area between two curves
§Examples
use plotpy::{Curve, FillBetween, Plot, StrError, linspace};
fn main() -> Result<(), StrError> {
// data and curve
let x = linspace(-1.0, 2.0, 21);
let y: Vec<_> = x.iter().map(|&x| x * x).collect();
let mut curve = Curve::new();
curve.set_line_color("black").draw(&x, &y);
// draw area between curve and x-axis
// (note that we have to use "y1" as variable name for the curve)
let mut fb = FillBetween::new();
fb.set_where("y1>=0.5").set_extra("alpha=0.5").draw(&x, &y, None);
// add curve and fb to plot
let mut plot = Plot::new();
plot.add(&curve).add(&fb);
// save figure
plot.save("/tmp/plotpy/doc_tests/doc_fill_between.svg")?;
Ok(())
}Implementations§
Source§impl FillBetween
impl FillBetween
Sourcepub fn draw<'a, T, U>(&mut self, x: &'a T, y1: &'a T, y2: Option<&'a T>)
pub fn draw<'a, T, U>(&mut self, x: &'a T, y1: &'a T, y2: Option<&'a T>)
Draws the filled area between two curves
x- x valuesy1- y values of the first curvey2- optional y values of the second curve. If None, fills area between y1 and x-axis
Sourcepub fn set_where(&mut self, condition: &str) -> &mut Self
pub fn set_where(&mut self, condition: &str) -> &mut Self
Sets the condition to select the area to be filled.
For example: “y2>=y1” or “y2<=y1”
WARNING: condition must use y1 and y2 as variable names for the two curves.
Sourcepub fn set_facecolor(&mut self, color: &str) -> &mut Self
pub fn set_facecolor(&mut self, color: &str) -> &mut Self
Sets the face color of the filled area.
Sourcepub fn set_interpolate(&mut self, interpolate: bool) -> &mut Self
pub fn set_interpolate(&mut self, interpolate: bool) -> &mut Self
Calculates the actual intersection point and extend the filled region up to this point.
From https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.fill_between.html:
“This option is only relevant if where is used and the two curves are crossing each other. Semantically,
where is often used for y1 > y2 or similar. By default, the nodes of the polygon defining the filled
region will only be placed at the positions in the x array. Such a polygon cannot describe the above
semantics close to the intersection. The x-sections containing the intersection are simply clipped.”
Default is false.
Sourcepub fn set_extra(&mut self, extra: &str) -> &mut Self
pub fn set_extra(&mut self, extra: &str) -> &mut Self
Fills the area between two curves
WARNING: where_condition must use y1 and y2 as variable names for the two curves.
For example:
curve.fill_between(x, y1, y2, "y2>=y1", "#ffaabb", true, "");
curve.fill_between(x, y1, y2, "y2>=y1", "#ffaabb", true, "");
curve.fill_between(x, y1, y2b, "y2<=y1", "#c1e3ff", true, "");Note: This method does not use the options of the Curve object.
See more options in https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.fill_between.html