Figure

Struct Figure 

Source
pub struct Figure { /* private fields */ }
Expand description

Figure.

Implementations§

Source§

impl Figure

Source

pub fn new(traces: Vec<Trace>, format: Format) -> Figure

Constructor.

§Arguments
  • traces - Traces to plot on the figure.
  • format - Formatting.
§Returns

Figure.

§Example
use plotting::{Color, Figure, Format, FormatBuilder, LineStyle, NamedColor, Trace};

// Define the traces.
let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
    .name("Trace 1")
    .line_color(Color::named(NamedColor::Red))
    .line_width(2.0)
    .line_style(LineStyle::Dash);
let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
    .name("Trace 2")
    .line_color(Color::named(NamedColor::Blue))
    .line_width(2.0)
    .line_style(LineStyle::Dot);

// Figure formatting.
let format: Format = FormatBuilder::default()
    .title("z vs. x and y")
    .x_label("x")
    .y_label("y")
    .z_label("z")
    .width(800)
    .height(600)
    .build()
    .unwrap();

// Create the figure.
let fig = Figure::new(vec![trace_1, trace_2], format);
Examples found in repository?
examples/general_2d_plot.rs (line 28)
4fn main() {
5    // Define the traces.
6    let trace_1 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 2.0, 3.0])
7        .name("y = x")
8        .line_color(Color::named(NamedColor::Red))
9        .line_width(2.0)
10        .line_style(LineStyle::Dash);
11    let trace_2 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0])
12        .name("y = x^2")
13        .line_color(Color::named(NamedColor::Blue))
14        .line_width(2.0)
15        .line_style(LineStyle::Dot);
16
17    // Figure formatting.
18    let format: Format = FormatBuilder::default()
19        .title("y vs. x")
20        .x_label("x")
21        .y_label("y")
22        .width(800)
23        .height(600)
24        .build()
25        .unwrap();
26
27    // Create the figure.
28    let fig = Figure::new(vec![trace_1, trace_2], format);
29
30    // Save the figure so it can be displayed right below this example.
31    fig.save_inline_html(Path::new("book/src/figures/general_2d_plot.html"));
32
33    // Alternatively, you can show the figure in a web browser.
34    // fig.show();
35}
More examples
Hide additional examples
examples/general_3d_plot.rs (line 29)
4fn main() {
5    // Define the traces.
6    let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
7        .name("Trace 1")
8        .line_color(Color::named(NamedColor::Red))
9        .line_width(2.0)
10        .line_style(LineStyle::Dash);
11    let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
12        .name("Trace 2")
13        .line_color(Color::named(NamedColor::Blue))
14        .line_width(2.0)
15        .line_style(LineStyle::Dot);
16
17    // Figure formatting.
18    let format: Format = FormatBuilder::default()
19        .title("z vs. x and y")
20        .x_label("x")
21        .y_label("y")
22        .z_label("z")
23        .width(800)
24        .height(600)
25        .build()
26        .unwrap();
27
28    // Create the figure.
29    let fig = Figure::new(vec![trace_1, trace_2], format);
30
31    // Save the figure so it can be displayed right below this example.
32    fig.save_inline_html(Path::new("book/src/figures/general_3d_plot.html"));
33
34    // Alternatively, you can show the figure in a web browser.
35    // fig.show();
36}
Source

pub fn plotly(&self) -> Plot

Create a plotly plot from the figure.

§Returns

Plotly plot.

Source

pub fn show(&self)

Show the figure (opens the figure in a web browser).

§Example
use plotting::{quick_plot_3d, Figure};

// Create a quick 3D plot with a single trace.
let fig: Figure = quick_plot_3d([1.0, 2.0, 10.0], [1.0, 4.0, 9.0], [2.0, 5.0, 10.0]);

// Show the figure (will open in a web browser).
fig.show();
Source

pub fn save_html<P: AsRef<Path>>(&self, path: P)

Save the figure to a standalone HTML file.

§Arguments
  • path - Path to the HTML file.
§Panics

If some error is encountered while creating the file or writing to it.

§Example
use plotting::{quick_plot_3d, Figure};

// Create a quick 3D plot with a single trace.
let fig: Figure = quick_plot_3d([1.0, 2.0, 10.0], [1.0, 4.0, 9.0], [2.0, 5.0, 10.0]);

// Save the figure to an HTML file.
fig.save_html("folder/file.html");
Source

pub fn save_inline_html<P: AsRef<Path>>(&self, path: P)

Save the figure to an HTML file meant to be used “in-line” in another HTML file.

§Arguments
  • path - Path to the HTML file.
§Panics

If some error is encountered while creating the file or writing to it.

§Example
use plotting::{quick_plot_3d, Figure};

// Create a quick 3D plot with a single trace.
let fig: Figure = quick_plot_3d([1.0, 2.0, 10.0], [1.0, 4.0, 9.0], [2.0, 5.0, 10.0]);

// Save the figure to an HTML file.
fig.save_inline_html("folder/file.html");
Examples found in repository?
examples/quick_plot_2d.rs (line 9)
4fn main() {
5    // Create the figure.
6    let fig: Figure = quick_plot_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0]);
7
8    // Save the figure so it can be displayed right below this example.
9    fig.save_inline_html(Path::new("book/src/figures/quick_plot_2d.html"));
10
11    // Alternatively, you can show the figure in a web browser.
12    // fig.show();
13}
More examples
Hide additional examples
examples/quick_plot_3d.rs (line 9)
4fn main() {
5    // Create the figure.
6    let fig: Figure = quick_plot_3d([1.0, 2.0, 10.0], [1.0, 4.0, 9.0], [2.0, 5.0, 10.0]);
7
8    // Save the figure so it can be displayed right below this example.
9    fig.save_inline_html(Path::new("book/src/figures/quick_plot_3d.html"));
10
11    // Alternatively, you can show the figure in a web browser.
12    // fig.show();
13}
examples/quick_plot_2d_with_labels.rs (line 10)
4fn main() {
5    // Create the figure.
6    let fig: Figure =
7        quick_plot_2d_with_labels([1.0, 2.0, 3.0], [1.0, 4.0, 9.0], "x", "y", "y = x^2");
8
9    // Save the figure so it can be displayed right below this example.
10    fig.save_inline_html(Path::new("book/src/figures/quick_plot_2d_with_labels.html"));
11
12    // Alternatively, you can show the figure in a web browser.
13    // fig.show();
14}
examples/quick_plot_3d_with_labels.rs (line 17)
4fn main() {
5    // Create the figure.
6    let fig: Figure = quick_plot_3d_with_labels(
7        [1.0, 2.0, 10.0],
8        [1.0, 4.0, 9.0],
9        [2.0, 5.0, 10.0],
10        "x",
11        "y",
12        "z",
13        "z vs. x and y",
14    );
15
16    // Save the figure so it can be displayed right below this example.
17    fig.save_inline_html(Path::new("book/src/figures/quick_plot_3d_with_labels.html"));
18
19    // Alternatively, you can show the figure in a web browser.
20    // fig.show();
21}
examples/general_2d_plot.rs (line 31)
4fn main() {
5    // Define the traces.
6    let trace_1 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 2.0, 3.0])
7        .name("y = x")
8        .line_color(Color::named(NamedColor::Red))
9        .line_width(2.0)
10        .line_style(LineStyle::Dash);
11    let trace_2 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0])
12        .name("y = x^2")
13        .line_color(Color::named(NamedColor::Blue))
14        .line_width(2.0)
15        .line_style(LineStyle::Dot);
16
17    // Figure formatting.
18    let format: Format = FormatBuilder::default()
19        .title("y vs. x")
20        .x_label("x")
21        .y_label("y")
22        .width(800)
23        .height(600)
24        .build()
25        .unwrap();
26
27    // Create the figure.
28    let fig = Figure::new(vec![trace_1, trace_2], format);
29
30    // Save the figure so it can be displayed right below this example.
31    fig.save_inline_html(Path::new("book/src/figures/general_2d_plot.html"));
32
33    // Alternatively, you can show the figure in a web browser.
34    // fig.show();
35}
examples/general_3d_plot.rs (line 32)
4fn main() {
5    // Define the traces.
6    let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
7        .name("Trace 1")
8        .line_color(Color::named(NamedColor::Red))
9        .line_width(2.0)
10        .line_style(LineStyle::Dash);
11    let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
12        .name("Trace 2")
13        .line_color(Color::named(NamedColor::Blue))
14        .line_width(2.0)
15        .line_style(LineStyle::Dot);
16
17    // Figure formatting.
18    let format: Format = FormatBuilder::default()
19        .title("z vs. x and y")
20        .x_label("x")
21        .y_label("y")
22        .z_label("z")
23        .width(800)
24        .height(600)
25        .build()
26        .unwrap();
27
28    // Create the figure.
29    let fig = Figure::new(vec![trace_1, trace_2], format);
30
31    // Save the figure so it can be displayed right below this example.
32    fig.save_inline_html(Path::new("book/src/figures/general_3d_plot.html"));
33
34    // Alternatively, you can show the figure in a web browser.
35    // fig.show();
36}

Auto Trait Implementations§

§

impl Freeze for Figure

§

impl RefUnwindSafe for Figure

§

impl Send for Figure

§

impl Sync for Figure

§

impl Unpin for Figure

§

impl UnwindSafe for Figure

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

Source§

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

Source§

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.