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

Plot is a container for structs that implement the Trace trait. Optionally a Layout can also be specified. Its function is to serialize Traces and the Layout in html format and display and/or persist the resulting plot.

Examples

use plotly::common::Mode;
use plotly::{Layout, Plot, Scatter};

fn line_and_scatter_plot() {
    let trace1 = Scatter::new(vec![1, 2, 3, 4], vec![10, 15, 13, 17])
        .name("trace1")
        .mode(Mode::Markers);
    let trace2 = Scatter::new(vec![2, 3, 4, 5], vec![16, 5, 11, 9])
        .name("trace2")
        .mode(Mode::Lines);
    let trace3 = Scatter::new(vec![1, 2, 3, 4], vec![12, 9, 15, 12])
        .name("trace3");

    let mut plot = Plot::new();
    plot.add_trace(trace1);
    plot.add_trace(trace2);
    plot.add_trace(trace3);

    let layout = Layout::new().title("<b>Line and Scatter Plot</b>".into());
    plot.set_layout(layout);

    plot.show();
}

fn main() -> std::io::Result<()> {
    line_and_scatter_plot();
    Ok(())
}

Implementations

Create a new Plot.

This option results in the plotly.js library being written directly in the html output. The benefit is that the plot will load faster in the browser and the downside is that the resulting html will be much larger.

Note that when using Plot::to_inline_html(), it is assumed that the plotly.js library is already in scope, so setting this attribute will have no effect.

Add a Trace to the Plot.

Add multiple Traces to the Plot.

Set the Layout to be used by Plot.

Set the Configuration to be used by Plot.

Get the contained data elements.

Get the layout specification of the plot.

Get the configuration specification of the plot.

Display the fully rendered HTML Plot in the default system browser.

The HTML file is saved in a temp file, from which it is read and displayed by the browser.

Display the fully rendered Plot as a static image of the given format in the default system browser.

Save the rendered Plot to a file at the given location.

This method will render the plot to a full, standalone HTML document, before saving it to the given location.

Convert a Plot to an HTML string representation.

This method will generate a full, standalone HTML document. To generate a minimal HTML string which can be embedded within an existing HTML page, use Plot::to_inline_html().

Renders the contents of the Plot and returns it as a String suitable for embedding within web pages or Jupyter notebooks.

A div is generated with the supplied id followed by the script block that generates the plot. The assumption is that plotly.js is available within the HTML page that this element is embedded. If that assumption is violated then the plot will not be displayed.

If plot_div_id is None the plot div id will be randomly generated, otherwise the user-supplied plot_div_id is used.

To generate a full, standalone HTML string or file, use Plot::to_html() and Plot::write_html(), respectively.

Display plot in Jupyter Notebook.

Display plot in Jupyter Lab.

Displays the plot in Jupyter Lab; if running a Jupyter Notebook then use the notebook_display() method instead.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.