pub struct SlopeIcon { /* private fields */ }
Expand description

Creates an icon to indicate the slope of lines

Notes

When using log scales, plot.set_log_x(true) or plot.set_log_y(true) must be called before adding the icon.

Example

use plotpy::{Curve, Plot, SlopeIcon, StrError};
use russell_lab::Vector;

fn main() -> Result<(), StrError> {
    // models
    let slope = 2.0;
    let (xi, xf, yi) = (0.0, 10.0, 0.0);
    let f = |x: f64| yi + slope * (x - xi);
    let g = |x: f64| f(xf) - slope * (x - xi);

    // curves
    let mut curve1 = Curve::new();
    let mut curve2 = Curve::new();
    let x = Vector::linspace(xi, xf, 3)?;
    let y1 = x.get_mapped(f);
    let y2 = x.get_mapped(g);
    curve1.set_marker_style("o").draw(&x, &y1);
    curve2.set_marker_style("*").draw(&x, &y2);

    // icons
    let mut icon1 = SlopeIcon::new();
    let mut icon2 = SlopeIcon::new();
    let mut icon3 = SlopeIcon::new();
    let mut icon4 = SlopeIcon::new();
    icon2.set_above(true);
    icon4.set_above(true);
    icon1.draw(slope, 2.5, f(2.5));
    icon2.draw(slope, 7.5, f(7.5));
    icon3.draw(-slope, 2.5, g(2.5));
    icon4.draw(-slope, 7.5, g(7.5));

    // plot
    let mut plot = Plot::new();
    plot.set_horizontal_gap(0.2);
    plot.set_subplot(2, 2, 1)
        .add(&curve1)
        .add(&curve2)
        .add(&icon1)
        .add(&icon2)
        .add(&icon3)
        .add(&icon4)
        .grid_and_labels("x", "y");

    // save figure
    plot.save("/tmp/plotpy/doc_tests/doc_slope_icon.svg")?;
    Ok(())
}

doc_slope_icon.svg

See also integration test in the tests directory.

Output from some integration tests:

integ_slope_icon_above.svg

integ_slope_icon_below.svg

integ_slope_icon_example.svg

integ_slope_icon_linx_liny.svg

integ_slope_icon_logx_logy.svg

Implementations

Creates a new SlopeIcon object

Draws an icon of line slope

Sets option to draw icon above line

Sets the color of icon lines

Sets the color of icon face

Sets the style of lines

Options:

Sets the width of lines

Sets the (horizontal) length of the icon in Axes coordinates [0, 1]

Sets the whole icon’s offset in normalized axes coordinates in points

Sets option to skip drawing text

Sets the font size

Sets the the precision of slope number in label

Sets text of horizontal value (== 1)

Sets text of vertical value (slope)

Sets the color of text

Sets the horizontal offset for the text in normalized axes coordinates in points

Sets the vertical offset for the text in normalized axes coordinates in points

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.