A plotting library for Rust powered by Plotly.js.
Documentation and numerous interactive examples are available in the Plotly.rs Book, the examples/ directory and docs.rs.
For changes since the last version, please consult the changelog.
Add this to your Cargo.toml
:
[dependencies]
plotly = "0.8.4"
Any figure can be saved as an HTML file using the Plot.write_html()
method. These HTML files can be opened in any web browser to access the fully interactive figure.
use plotly::{Plot, Scatter};
let mut plot = Plot::new();
let trace = Scatter::new(vec![0, 1, 2], vec![2, 1, 0]);
plot.add_trace(trace);
plot.write_html("out.html");
By default, the Plotly JavaScript library will be included via CDN, which results in a smaller filesize, but slightly slower first load as the JavaScript library has to be downloaded first. To instead embed the JavaScript library (several megabytes in size) directly into the HTML file, the following can be done:
// <-- Create a `Plot` -->
plot.use_local_plotly();
plot.write_html("out.html");
If you only want to view the plot in the browser quickly, use the Plot.show()
method.
// <-- Create a `Plot` -->
plot.show(); // The default web browser will open, displaying an interactive plot