Struct plotpy::Plot

source · []
pub struct Plot { /* private fields */ }
Expand description

Driver structure that calls Python

Example

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

fn main() -> Result<(), StrError> {
    // generate (x,y) points
    let n = 11;
    let x = Vector::linspace(-1.0, 1.0, n)?;
    let y1 = x.clone();
    let y2 = x.get_mapped(|v| f64::abs(v));
    let y3 = x.get_mapped(|v| f64::exp(1.0 + v) - 1.0);
    let y4 = x.get_mapped(|v| f64::sqrt(1.0 + v));

    // configure and draw curves
    let mut curve1 = Curve::new();
    let mut curve2 = Curve::new();
    let mut curve3 = Curve::new();
    let mut curve4 = Curve::new();
    curve1.set_label("y = x");
    curve2.set_label("y = |x|").set_line_color("#cd0000");
    curve3.set_label("y = exp(1+x)-1").set_line_color("#e79955");
    curve4.set_label("y = sqrt(1+x)").set_line_color("#b566ab");
    curve1.draw(&x, &y1);
    curve2.draw(&x, &y2);
    curve3.draw(&x, &y3);
    curve4.draw(&x, &y4);

    // configure plot
    let mut plot = Plot::new();
    plot.set_super_title("FOUR CURVES").set_gaps(0.35, 0.5);

    // add curve to subplot
    plot.set_subplot(2, 2, 1)
        .set_title("first")
        .add(&curve1)
        .grid_labels_legend("x", "y")
        .set_equal_axes(true);

    // add curve to subplot
    plot.set_subplot(2, 2, 2)
        .set_title("second")
        .add(&curve2)
        .grid_labels_legend("x", "y");

    // add curve to subplot
    plot.set_subplot(2, 2, 3)
        .set_title("third")
        .add(&curve3)
        .set_range(-1.0, 1.0, 0.0, 6.0)
        .grid_labels_legend("x", "y");

    // add curve to subplot
    plot.set_subplot(2, 2, 4)
        .set_title("fourth")
        .add(&curve4)
        .grid_labels_legend("x", "y");

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

doc_plot.svg

See also integration tests in the tests directory

Implementations

Creates new Plot object

Adds new graph entity

Calls python3 and saves the python script and figure

Input
  • figure_path – may be a String, &str, or Path
Note

Call set_show_errors to configure how the errors (if any) are printed.

Calls python3, saves the python script and figure, and show the plot window

Input
  • figure_path – may be a String, &str, or Path
Note

Call set_show_errors to configure how the errors (if any) are printed.

Clears current figure

Adds legend to plot (see Legend for further options)

Adds grid and labels

Adds grid, labels, and legend

Sets flag to print python errors (if any) when calling save

Configures subplots

Arguments
  • row - number of rows in the subplot grid
  • col - number of columns in the subplot grid
  • index - activate current subplot; indices start at one (1-based)

Adds a title to the plot or sub-plot

Adds a title to all sub-plots

Sets the horizontal gap between subplots

Sets the vertical gap between subplots

Sets the horizontal and vertical gap between subplots

Sets same scale for both axes

Sets the figure size in inches

Sets the figure size in points

Set option to hide axes

Sets axes limits

Sets axes limits

Sets axes limits from vector

Sets minimum x

Sets maximum x

Sets minimum y

Sets maximum y

Sets x-range (i.e. limits)

Sets y-range (i.e. limits)

Sets number of ticks along x

Sets number of ticks along y

Sets the number and format of x-ticks

Input
  • major_every – step for major ticks (ignored if ≤ 0.0)
  • minor_every – step for major ticks (ignored if ≤ 0.0)
  • major_number_format – C-style number format for major ticks; e.g. “%.2f” (ignored if empty “”) See matplotlib FormatStrFormatter

Sets the number and format of y-ticks

Input
  • major_every – step for major ticks (ignored if ≤ 0.0)
  • minor_every – step for major ticks (ignored if ≤ 0.0)
  • major_number_format – C-style number format for major ticks; e.g. “%.2f” (ignored if empty “”) See matplotlib FormatStrFormatter

Sets the x-ticks to multiples of pi

Input
  • minor_every – step for major ticks (ignored if ≤ 0.0). Example PI / 12.0

Note: This function sets the major ticks as PI / 2.0.

Sets the y-ticks to multiples of pi

Input
  • minor_every – step for major ticks (ignored if ≤ 0.0). Example PI / 12.0

Note: This function sets the major ticks as PI / 2.0.

Sets a log10 x-scale

Note

set_log_x(true) must be called before adding curves.

Sets a log10 y-scale

Note

set_log_y(true) must be called before adding curves.

Sets the label for the x-axis

Sets the label for the y-axis

Sets the labels of x and y axis

Sets camera in 3d graph. Sets the elevation and azimuth of the axes.

Input
  • elev – is the elevation angle in the z plane
  • azimuth – is the azimuth angle in the x,y plane

Sets option to hide (or show) frame borders

Sets visibility of all frame borders

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.