Struct 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

extern crate plotly;
use plotly::common::Mode;
use plotly::{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);
    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.

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 show(&self)

Renders the contents of the Plot and displays them in the system default browser.

This will serialize the Traces and Layout in an html page which is saved in the temp directory. For example on Linux it will generate a file plotly_<22 random characters>.html in the /tmp directory.

Source

pub fn show_png(&self, width: usize, height: usize)

Renders the contents of the Plot, creates a png raster and displays it in the system default browser.

To save the resulting png right-click on the resulting image and select Save As....

Source

pub fn show_jpeg(&self, width: usize, height: usize)

Renders the contents of the Plot, creates a jpeg raster and displays it in the system default browser.

To save the resulting png right-click on the resulting image and select Save As....

Source

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

Renders the contents of the Plot and displays it in the system default browser.

In contrast to Plot::show() this will save the resulting html in a user specified location instead of the system temp directory.

In contrast to Plot::write_html, this will save the resulting html to a file located at a user specified location, instead of a writing it to anything that implements std::io::Write.

Source

pub fn write_html<W: Write>(&self, buffer: &mut W)

Renders the contents of the Plot to HTML and outputs them to a writable buffer.

In contrast to Plot::to_html, this will save the resulting html to a byte buffer using the std::io::Write trait, instead of to a user specified file.

Source

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

Renders the contents of the Plot and returns it as a String, for embedding in web-pages or Jupyter notebooks. A div is generated with the supplied id followed by the script 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 div id is used.

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 Default for Plot

Source§

fn default() -> Plot

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

Auto Trait Implementations§

§

impl Freeze for Plot

§

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

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

Source§

fn vzip(self) -> V