Struct plotly::plot::Plot

source ·
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§

source§

impl Plot

source

pub fn new() -> Plot

Create a new Plot.

source

pub fn use_local_plotly(&mut self)

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.

source

pub fn add_trace(&mut self, trace: Box<dyn Trace>)

Add a Trace to the Plot.

source

pub fn add_traces(&mut self, traces: Vec<Box<dyn Trace>>)

Add multiple Traces to the Plot.

source

pub fn set_layout(&mut self, layout: Layout)

Set the Layout to be used by Plot.

source

pub fn set_configuration(&mut self, configuration: Configuration)

Set the Configuration to be used by Plot.

source

pub fn data(&self) -> &Traces

Get the contained data elements.

source

pub fn layout(&self) -> &Layout

Get the layout specification of the plot.

source

pub fn configuration(&self) -> &Configuration

Get the configuration specification of the plot.

source

pub fn show(&self)

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.

source

pub fn show_image(&self, format: ImageFormat, width: usize, height: usize)

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

source

pub fn write_html<P: AsRef<Path>>(&self, filename: P)

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.

source

pub fn to_html(&self) -> String

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().

source

pub fn to_inline_html(&self, plot_div_id: Option<&str>) -> String

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.

source

pub fn notebook_display(&self)

Display plot in Jupyter Notebook.

source

pub fn lab_display(&self)

Display plot in Jupyter Lab.

source

pub fn evcxr_display(&self)

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

source

pub fn to_json(&self) -> String

Trait Implementations§

source§

impl Clone for Plot

source§

fn clone(&self) -> Plot

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Plot

source§

fn default() -> Plot

Returns the “default value” for a type. Read more
source§

impl PartialEq<Plot> for Plot

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Plot

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Plot

§

impl !Send for Plot

§

impl !Sync for Plot

§

impl Unpin for Plot

§

impl !UnwindSafe for Plot

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Serialize for Twhere T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V