FillBetween

Struct FillBetween 

Source
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(())
}

doc_fill_between.svg

Implementations§

Source§

impl FillBetween

Source

pub fn new() -> Self

Allocates a new instance

Source

pub fn draw<'a, T, U>(&mut self, x: &'a T, y1: &'a T, y2: Option<&'a T>)
where T: AsVector<'a, U>, U: 'a + Display + Num,

Draws the filled area between two curves

  • x - x values
  • y1 - y values of the first curve
  • y2 - optional y values of the second curve. If None, fills area between y1 and x-axis
Source

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.

Source

pub fn set_facecolor(&mut self, color: &str) -> &mut Self

Sets the face color of the filled area.

Source

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.

Source

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

Trait Implementations§

Source§

impl GraphMaker for FillBetween

Source§

fn get_buffer<'a>(&'a self) -> &'a String

Returns the text buffer with Python3 commands
Source§

fn clear_buffer(&mut self)

Clear the text buffer with Python commands

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.