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

Generates a curve (aka line-plot) given two arrays (x,y)

Notes

  • This struct corresponds to the plot function of Matplotlib.
  • You may plot a Scatter plot by setting line_style = “None”

Examples

Using methods to set the points

use plotpy::{Curve, Plot, StrError};
use std::f64::consts::PI;

fn main() -> Result<(), StrError> {
    // configure curve
    let mut curve = Curve::new();
    curve.set_line_width(2.0);

    // add points
    const N: usize = 30;
    curve.points_begin();
    for i in 0..N {
        let x = (i as f64) * 2.0 * PI / ((N - 1) as f64);
        let y = f64::sin(x);
        curve.points_add(x, y);
    }
    curve.points_end();

    // add curve to plot
    let mut plot = Plot::new();
    plot.add(&curve).grid_and_labels("x", "y");

    // configure multiple-of-pi formatter
    let minor_every = PI / 12.0;
    plot.set_ticks_x_multiple_of_pi(minor_every);

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

doc_curve_methods.svg

Using Vector with point data

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

fn main() -> Result<(), StrError> {
    // generate (x,y) points
    let x = Vector::linspace(-1.0, 1.0, 21)?;
    let y = x.get_mapped(|v| 1.0 / (1.0 + f64::exp(-5.0 * v)));

    // configure curve
    let mut curve = Curve::new();
    curve
        .set_label("logistic function")
        .set_line_alpha(0.8)
        .set_line_color("#5f9cd8")
        .set_line_style("-")
        .set_line_width(5.0)
        .set_marker_color("#eeea83")
        .set_marker_every(5)
        .set_marker_line_color("#da98d1")
        .set_marker_line_width(2.5)
        .set_marker_size(20.0)
        .set_marker_style("*");

    // draw curve
    curve.draw(&x, &y);

    // add curve to plot
    let mut plot = Plot::new();
    plot.add(&curve).set_num_ticks_y(11).grid_labels_legend("x", "y");

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

doc_curve_vector.svg

See also integration tests in the tests directory

Output from some integration tests:

integ_curve.svg

integ_curve_3d.svg

Implementations

Creates new Curve object

Begins adding points to the curve (2D only)

Warning

This function must be followed by Curve::points_add and Curve::points_end, otherwise Python/Matplotlib will fail.

Adds point to the curve (2D only)

Warning

This function must be called after Curve::points_begin and must be followed by Curve::points_end, otherwise Python/Matplotlib will fail.

Ends adding points to the curve (2D only)

Warning

This function must be called after Curve::points_begin and Curve::points_add, otherwise Python/Matplotlib will fail.

Begins adding 3D points to the curve

Warning

This function must be followed by Curve::points_3d_add and Curve::points_3d_end, otherwise Python/Matplotlib will fail

Adds 3D point to the curve

Warning

This function must be called after Curve::points_3d_begin and must be followed by Curve::points_3d_end, otherwise Python/Matplotlib will fail.

Ends adding 3D points to the curve

Warning

This function must be called after Curve::points_3d_begin and Curve::points_3d_add, otherwise Python/Matplotlib will fail.

Draws curve

Input
  • x - abscissa values
  • y - ordinate values
Notes
  • The type U of the input array must be a number.

Draws curve in 3D plot

Input
  • x - x values
  • y - y values
  • z - z values
Notes
  • The type U of the input array must be a number.

Sets the name of this curve in the legend

Sets the opacity of lines (0, 1]. A<1e-14 => A=1.0

Sets the color of lines

Draws a ray (an infinite line)

  • For horizontal rays, only ya is used
  • For vertical rays, only xa is used

Sets the style of lines

Options:

Sets the width of lines

Sets the color of markers

Sets the increment of data points to use when drawing markers

Sets the option to draw a void marker (draw edge only)

Sets the edge color of markers

Sets the edge width of markers

Sets the size of markers

Sets the style of markers

Examples:

Sets the flag to stop clipping features within margins

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.