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(())
}See also integration test in the tests directory.
Output from some integration tests:
Implementations
sourceimpl SlopeIcon
impl SlopeIcon
sourcepub fn set_edge_color(&mut self, color: &str) -> &mut Self
pub fn set_edge_color(&mut self, color: &str) -> &mut Self
Sets the color of icon lines
sourcepub fn set_face_color(&mut self, color: &str) -> &mut Self
pub fn set_face_color(&mut self, color: &str) -> &mut Self
Sets the color of icon face
sourcepub fn set_line_style(&mut self, style: &str) -> &mut Self
pub fn set_line_style(&mut self, style: &str) -> &mut Self
Sets the style of lines
Options:
- “
-”,:“, “--”, “-.”, or “None” - As defined in https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html
sourcepub fn set_line_width(&mut self, width: f64) -> &mut Self
pub fn set_line_width(&mut self, width: f64) -> &mut Self
Sets the width of lines
sourcepub fn set_length(&mut self, value: f64) -> &mut Self
pub fn set_length(&mut self, value: f64) -> &mut Self
Sets the (horizontal) length of the icon in Axes coordinates [0, 1]
sourcepub fn set_offset_v(&mut self, value: f64) -> &mut Self
pub fn set_offset_v(&mut self, value: f64) -> &mut Self
Sets the whole icon’s offset in normalized axes coordinates in points
sourcepub fn set_no_text(&mut self, flag: bool) -> &mut Self
pub fn set_no_text(&mut self, flag: bool) -> &mut Self
Sets option to skip drawing text
sourcepub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self
pub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self
Sets the font size
sourcepub fn set_precision(&mut self, value: usize) -> &mut Self
pub fn set_precision(&mut self, value: usize) -> &mut Self
Sets the the precision of slope number in label
sourcepub fn set_text_h(&mut self, one: &str) -> &mut Self
pub fn set_text_h(&mut self, one: &str) -> &mut Self
Sets text of horizontal value (== 1)
sourcepub fn set_text_v(&mut self, slope: &str) -> &mut Self
pub fn set_text_v(&mut self, slope: &str) -> &mut Self
Sets text of vertical value (slope)
sourcepub fn set_text_color(&mut self, color: &str) -> &mut Self
pub fn set_text_color(&mut self, color: &str) -> &mut Self
Sets the color of text
sourcepub fn set_text_offset_h(&mut self, value: f64) -> &mut Self
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
sourcepub fn set_text_offset_v(&mut self, value: f64) -> &mut Self
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
sourceimpl GraphMaker for SlopeIcon
impl GraphMaker for SlopeIcon
sourcefn get_buffer<'a>(&'a self) -> &'a String
fn get_buffer<'a>(&'a self) -> &'a String
Returns the text buffer with Python3 commands
sourcefn clear_buffer(&mut self)
fn clear_buffer(&mut self)
Clear the text buffer with Python commands
Auto Trait Implementations
impl RefUnwindSafe for SlopeIcon
impl Send for SlopeIcon
impl Sync for SlopeIcon
impl Unpin for SlopeIcon
impl UnwindSafe for SlopeIcon
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more