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 Trace
s 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>");
plot.set_layout(layout);
plot.show();
}
fn main() -> std::io::Result<()> {
line_and_scatter_plot();
Ok(())
}
Implementations§
Source§impl Plot
impl Plot
Sourcepub fn add_traces(&mut self, traces: Vec<Box<dyn Trace>>)
pub fn add_traces(&mut self, traces: Vec<Box<dyn Trace>>)
Add multiple Trace
s to the Plot
.
Sourcepub fn set_layout(&mut self, layout: Layout)
pub fn set_layout(&mut self, layout: Layout)
Set the Layout
to be used by Plot
.
Sourcepub fn set_configuration(&mut self, configuration: Configuration)
pub fn set_configuration(&mut self, configuration: Configuration)
Set the Configuration
to be used by Plot
.
Sourcepub fn configuration(&self) -> &Configuration
pub fn configuration(&self) -> &Configuration
Get the configuration specification of the plot.
Sourcepub fn show(&self)
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.
Sourcepub fn show_html<P: AsRef<Path> + Clone>(&self, filename: P)
pub fn show_html<P: AsRef<Path> + Clone>(&self, filename: P)
Display the fully rendered HTML Plot
in the default system browser.
The HTML file is generated and saved in the provided filename as long as the path already exists, after the file is saved, it is read and displayed by the browser.
Sourcepub fn show_image(&self, format: ImageFormat, width: usize, height: usize)
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.
Sourcepub fn write_html<P: AsRef<Path>>(&self, filename: P)
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.
Sourcepub fn to_html(&self) -> String
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()
.
Sourcepub fn to_inline_html(&self, plot_div_id: Option<&str>) -> String
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.
Sourcepub fn notebook_display(&self)
pub fn notebook_display(&self)
Display plot in Jupyter Notebook.
Sourcepub fn lab_display(&self)
pub fn lab_display(&self)
Display plot in Jupyter Lab.
Sourcepub fn evcxr_display(&self)
pub fn evcxr_display(&self)
Displays the plot in Jupyter Lab; if running a Jupyter Notebook then use
the notebook_display()
method instead.