Struct plotpy::SlopeIcon

source ·
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::{linspace, Curve, Plot, SlopeIcon, StrError};

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 = linspace(xi, xf, 3);
    let y1: Vec<_> = x.iter().map(|x| f(*x)).collect();
    let y2: Vec<_> = x.iter().map(|x| g(*x)).collect();
    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§

source§

impl SlopeIcon

source

pub fn new() -> Self

Creates a new SlopeIcon object

source

pub fn draw(&mut self, slope: f64, x_center: f64, y_center: f64)

Draws an icon of line slope

source

pub fn set_above(&mut self, flag: bool) -> &mut Self

Sets option to draw icon above line

source

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

Sets the color of icon lines

source

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

Sets the color of icon face

source

pub fn set_line_style(&mut self, style: &str) -> &mut Self

Sets the style of lines

Options:

source

pub fn set_line_width(&mut self, width: f64) -> &mut Self

Sets the width of lines

source

pub fn set_length(&mut self, value: f64) -> &mut Self

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

source

pub fn set_offset_v(&mut self, value: f64) -> &mut Self

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

source

pub fn set_no_text(&mut self, flag: bool) -> &mut Self

Sets option to skip drawing text

source

pub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self

Sets the font size

source

pub fn set_precision(&mut self, value: usize) -> &mut Self

Sets the the precision of slope number in label

source

pub fn set_text_h(&mut self, one: &str) -> &mut Self

Sets text of horizontal value (== 1)

source

pub fn set_text_v(&mut self, slope: &str) -> &mut Self

Sets text of vertical value (slope)

source

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

Sets the color of text

source

pub fn set_text_offset_h(&mut self, value: f64) -> &mut Self

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

source

pub fn set_text_offset_v(&mut self, value: f64) -> &mut Self

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

Trait Implementations§

source§

impl GraphMaker for SlopeIcon

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>,

§

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>,

§

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.