13 unstable releases

0.8.4 Jul 9, 2023
0.8.3 Nov 6, 2022
0.8.1 Sep 25, 2022
0.7.0 Jan 1, 2022
0.4.1 Mar 26, 2020

#2 in Visualization

Download history 799/week @ 2023-08-16 828/week @ 2023-08-23 993/week @ 2023-08-30 920/week @ 2023-09-06 1345/week @ 2023-09-13 1024/week @ 2023-09-20 1206/week @ 2023-09-27 1003/week @ 2023-10-04 1060/week @ 2023-10-11 997/week @ 2023-10-18 1203/week @ 2023-10-25 1139/week @ 2023-11-01 1058/week @ 2023-11-08 1219/week @ 2023-11-15 1444/week @ 2023-11-22 961/week @ 2023-11-29

4,921 downloads per month
Used in 22 crates

MIT license

11K SLoC


Plotly for Rust

Build status Crates.io Downloads Documentation Code coverage

Getting Started | Recipes | API Docs | Changelog

Table of Contents


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.

Basic Usage

Add this to your Cargo.toml:

plotly = "0.8.4"

Exporting an Interactive Plot

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]);


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` -->


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

Exporting a Static Image

To save a plot as a static image, the kaleido feature is required:

# Cargo.toml

plotly = { version = "0.8.4", features = ["kaleido"] }

With this feature enabled, plots can be saved as any of png, jpeg, webp, svg, pdf and eps. Note that the plot will be a static image, i.e. they will be non-interactive.

The Kaleido binary is downloaded for your system's architecture at compile time from the official Kaleido release page. This library currently supports x86_64 on Linux and Windows, and both x86_64 and aarch64 on macOS.

Exporting a simple plot looks like this:

use plotly::{ImageFormat, Plot};

let mut plot = Plot::new();
let trace = Scatter::new(vec![0, 1, 2], vec![2, 1, 0]);

plot.write_image("out.png", ImageFormat::PNG, 800, 600, 1.0);

Usage Within a Wasm Environment

Using Plotly.rs in a Wasm-based frontend framework is possible by enabling the wasm feature:

# Cargo.toml

plotly = { version = "0.8.4", features = ["wasm"] }

First, make sure that you have the Plotly JavaScript library in your base HTML template:

 <!-- index.html -->

<!doctype html>
<html lang="en">
        <!-- snip -->
        <script src="https://cdn.plot.ly/plotly-2.14.0.min.js"></script>
    <!-- snip -->

A simple Plot component would look as follows, using Yew as an example frontend framework:

use plotly::{Plot, Scatter};
use yew::prelude::*;

pub fn plot_component() -> Html {
    let p = yew_hooks::use_async::<_, _, ()>({
        let id = "plot-div";
        let mut plot = Plot::new();
        let trace = Scatter::new(vec![0, 1, 2], vec![2, 1, 0]);

        async move {
            plotly::bindings::new_plot(id, &plot).await;

        use_effect_with_deps(move |_| {
            || ()
        }, (),

    html! {
        <div id="plot-div"></div>

More detailed standalone examples can be found in the examples/ directory.

Crate Feature Flags

The following feature flags are available:


Adds plot save functionality to the following formats: png, jpeg, webp, svg, pdf and eps.


Adds trait implementations so that image::RgbImage and image::RgbaImage can be used more directly with the plotly::Image trace.


Adds support for creating plots directly using ndarray types.


Enables compilation for the wasm32-unknown-unknown target and provides access to a bindings module containing wrappers around functions exported by the plotly.js library.


  • If you've spotted a bug or would like to see a new feature, please submit an issue on the issue tracker.

  • Pull requests are welcome, see the contributing guide for more information.


Plotly.rs is distributed under the terms of the MIT license.

See LICENSE-MIT, and COPYRIGHT for details.


~128K SLoC