Plotly for Rust

Overview

Plotly.rs

Plotly for Rust
build status | Crates.io | Documentation | Minimum Version

A plotting library for Rust powered by Plotly.js.

Usage

Add this to your Cargo.toml:

[dependencies]
plotly = "0.6.0"

For changes since the last version please consult the change log.

Crate Feature Flags

The following feature flags are available:

  • kaleido
    • Optional, compatible with Rust stable.
    • Adds plot save functionality to the following formats: png, jpeg, webp, svg, pdf and eps.
    • Requires some additional configuration, see plotly_kaleido.
  • plotly_ndarray
    • Optional, compatible with Rust stable.
    • Adds support for creating plots directly using ndarray types.

Saving to png, jpeg, webp, svg, pdf and eps formats can be made available by enabling the kaleido feature:

[dependencies]
plotly = { version = "0.6.0", features = ["kaleido"] }

For further details please see plotly_kaleido.

Contributing

Please consult the contributing guide.

License

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

See LICENSE-MIT, and COPYRIGHT for details.

Comments
  • plotly 0.8.1 seems not work with kaleido 0.3.0

    plotly 0.8.1 seems not work with kaleido 0.3.0

    Is there anything wrong with this?

    Envrionment: Toolchain: stable-x86_64-pc-windows-msvc Rust/Cargo: 1.64.0

    Steps to reproduce: cargo init app_name cd app_name cargo add plotly cargo add plotly --features kaleido cargo check

    Output: ....

       Compiling plotly_kaleido v0.3.0
        Checking plotly v0.8.1
    error[E0308]: mismatched types
       --> C:\Users\mwim\.cargo\registry\src\github.com-1ecc6299db9ec823\plotly-0.8.1\src\plot.rs:385:17
        |
    383 |             .save(
        |              ---- arguments to this function are incorrect
    384 |                 filename.as_ref(),
    385 |                 &serde_json::to_value(self).unwrap(),
        |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `str`, found enum `Value`
        |
        = note: expected reference `&str`
                   found reference `&Value`
    note: associated function defined here
       --> C:\Users\mwim\.cargo\registry\src\github.com-1ecc6299db9ec823\plotly_kaleido-0.3.0\src\lib.rs:124:12
        |
    124 |     pub fn save(
        |            ^^^^
    
    For more information about this error, try `rustc --explain E0308`.
    error: could not compile `plotly` due to previous error
    
    opened by m-wim 9
  • Attempting to save in PNG format causes panic

    Attempting to save in PNG format causes panic

    Hi,

    I have this in Cargo.toml:

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

    And, following the instructions, this in my code: plot.save(filename, ImageFormat::PNG, 1024, 768, 1.0);

    The program crashes with this:

    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /home/jgoerzen/.cargo/registry/src/github.com-1ecc6299db9ec823/plotly_kaleido-0.2.0/src/lib.rs:97:13
    

    That backtrace wasn't much help, but strace was:

    21466 lstat("/home", {st_mode=S_IFDIR|0755, st_size=10, ...}) = 0
    21466 lstat("/home/jgoerzen", {st_mode=S_IFDIR|0755, st_size=722, ...}) = 0
    21466 lstat("/home/jgoerzen/tree", {st_mode=S_IFDIR|0755, st_size=248, ...}) = 0
    21466 lstat("/home/jgoerzen/tree/plotly_kaleido", 0x7ffd64e387b0) = -1 ENOENT (No such file or directory)
    

    The current working directory was a different one under /home/jgoerzen/tree.

    Why it expects ../plotly_kaleido to exist, I don't know. What's supposed to be there, I also don't know. The plotly documentation said there was some additional configuration necessary for plotly_kaleido but the plotly_kaleido documentation doesn't say what it is. I couldn't find any documentation for how to set up plotly_kaleido or why it would be looking for something in ...

    Thanks for your work on this!

    opened by jgoerzen 9
  • Traces for Mesh3d, Image, ScatterMapbox

    Traces for Mesh3d, Image, ScatterMapbox

    Hi, I have implemented some basic wrapping code for go.Mesh3D and go.Image as suggested in #49. I used @mrhrzg's scatter3d.rs as a starting point.

    I am sending this pull request now to get some feedback. Should I do the following things to complete the added features? Anything else?

    • add one example for each new trace type
    • implement setters for all remaining parameters listed in the documentation
    • fix all cargo warnings
    • add entry in change log
    • run test suite

    Just before sending this I decided to also add some mapbox support, as suggested in #86. Specifically I started adding go.Scattermapbox. I am a little confused about layout.mapbox and layout.mapbox_style which seems to lack a documentation entry, and I have not been able to get layout.mapbox_style to work properly. I tried "stamen-watercolor" and "open-street-map" but they seem to have no effect. I guess it should be turned into an enum in the end, but this can't be the problem can it?

    By the way I am using Evcxr.

    Also by the way I think there is a fair bit of code duplication going on with parameters being repeated across different structs. Maybe this could be improved using some kind of rust macro? I guess the most difficult part of this might be to handle the documentation properly.

    opened by JoelSjogren 8
  • Stack overflows when adding colorbar to plot

    Stack overflows when adding colorbar to plot

    Hi, it's enjoyable to use this crate in plotting some scientific figures, and the experience was pleasant.

    Just now, I found it crashed when adding color bar to the plot and I'm not sure if this was a matter of my code. Would it be possible to bother you have a look at it?

    Here is the MWE:

    use plotly;
    
    fn main() {
        let x = (0 .. 100).collect::<Vec<_>>();
        let y = x.iter().map(|v| v * v).collect::<Vec<_>>();
        let c = x.iter().map(|v| (*v as f64).sqrt()).collect::<Vec<_>>();
    
        let tr = plotly::Scatter::new(x, y)
            .mode(plotly::common::Mode::Markers)
            .marker(plotly::common::Marker::new()
                    .color_bar(plotly::common::ColorBar::new())
                    .color_scale(plotly::common::ColorScale::Palette(plotly::common::ColorScalePalette::Jet))
                    .color_array(c));
    
        let mut plot = plotly::Plot::new();
        plot.add_trace(tr);
        plot.use_local_plotly();
    
        plot.show();
    }
    

    And it crashed:

    thread 'main' has overflowed its stack
    fatal runtime error: stack overflow
    [1]    39611 abort      cargo run --release
    

    Here is my environment:

    • macOS 10.15.7
    • rustc 1.59 stable
    • plotly 0.7
    opened by Ionizing 6
  • WASM Target compiliation

    WASM Target compiliation

    I'm using seed-rs to display plots with the inline html. seed-rs uses wasmpack which compile libraries with the wasm32-unknown-unknown target.

    Repo to reproduce the error

    error[E0599]: no function or associated item named `show_with_default_app` found for struct `plot::Plot` in the current scope
       --> C:\[...]\.cargo\git\checkouts\plotly-32f25712b3766afa\870dfc6\plotly\src\plot.rs:209:15
        |
    96  | pub struct Plot {
        | --------------- function or associated item `show_with_default_app` not found for this
    ...
    209 |         Plot::show_with_default_app(temp_path);
        |               ^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `plot::Plot`
    
    opened by ykafia 5
  • Extract the render-to-string portion of to_html() into its own public method

    Extract the render-to-string portion of to_html() into its own public method

    Add a .to_inline_html() method to Plot which can then be sent elsewhere for rendering.

    For example, when using in Evcxr this turns this construction:

    let plotly_file = "/tmp/plot.html";
    plot.to_html(plotly_file);
    let plotly_contents = fs::read_to_string(plotly_file).unwrap();
    println!("EVCXR_BEGIN_CONTENT text/html\n{}\nEVCXR_END_CONTENT", plotly_contents);
    fs::remove_file(plotly_file)?;
    

    into this one-liner:

    println!("EVCXR_BEGIN_CONTENT text/html\n{}\nEVCXR_END_CONTENT", plot.to_inline_html());
    

    I debated adding a helper method for that wrapping - I'm happy to do so but I feel it would be presumptive without an OK from @igiagkiozis since they might not wish to officially support such usage, and interested parties probably are using DARN anyway which is a better place for it.

    Closes #12 as long as people are happy to do their own root div or Evcxr content wrapping.

    opened by Xymist 5
  • Missing LegendGroupTitle on other trace types?

    Missing LegendGroupTitle on other trace types?

    The LegendGroupTitle seems only supported for Scatter3D and Sankey at this point. For example, the BoxPlot only offers to set a legend group. But there is no way to set the LegendGroupTitle? Is that on purpose or is it simply missing and should be added?

    opened by kaihowl 4
  • Display hundereds of plots

    Display hundereds of plots

    Yesterday I tried to write around 700 plots to an HTML file via calling to_inline_html() this many times into a vector of strings and then writing them all to an HTML template that only includes plotly.js once. My browser couldn't handle the resulting file very well. It is very slow. Are there any known tricks to make plotly behave more snappy in such situations? Or is this a complete misuse of the library on my part?

    opened by mindv0rtex 4
  • Panicked at 'Could not find default application for HTML files.`

    Panicked at 'Could not find default application for HTML files.`

    Tried to run this code

    fn main() -> Result<(), Box<dyn Error>> {
        line_and_scatter_plot();
        Ok(())
    }
    
    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();
    }
    

    It resulted in this error:

    thread 'main' panicked at 'Could not find default application for HTML files.
    Consider using the `to_html` method to save the plot instead. If using the `orca` feature the following
    additional formats are available accessed by following methods:
    - to_png
    - to_jpeg
    - to_webp
    - to_svg
    - to_pdf
    - to_eps
    : Os { code: 2, kind: NotFound, message: "No such file or directory" }', /home/nlam/.cargo/registry/src/github.com-1ecc6299db9ec823/plotly-0.5.1/src/plot.rs:454:14
    

    Operating System: Windows 10 Home Version 2002 - WSL 2.0 Ubuntu Browser: Normal FireFox Version 78.02(64-bit)

    opened by nlam1170 4
  • Shapes Support

    Shapes Support

    Id like to see this crate support shapes in Plotly (https://plotly.com/javascript/shapes/).

    Due to a failure to read the contributing file on my part I already made an implementation. My bad. I'll wait for discussion before making a PR.

    enhancement good first issue 
    opened by muroc 4
  • Documentation

    Documentation

    This is a great addition to the broader scientific computing ecosystem for Rust. I've not used plotly.js extensively, and I suspect a bunch of folks would want to try to use this crate without browsing the plotly-documentation.

    So I thought I'd attempt to explore this repo and make some documentation here and there. This issue is to gather ideas, strategy, or whatever needs to be taken into account in order to improve the documentation of this crate.

    For instance: Is there a dataset prelude that can be used to make examples with?

    documentation 
    opened by CGMossa 4
  • how to set cdn manually ?

    how to set cdn manually ?

    I found the default cdn was set in the plotly/templates/plot.html or static_plot.html, so is there any method in Plot to set the two cdn url in code ?

    opened by yinshurman 0
  • Bin size changes after making histogram overlaid

    Bin size changes after making histogram overlaid

    Hi,

    Thanks for this amazing crate! I am looking for suggestions on how to specify/synchronize the bin size for two histograms. When I plot just two histogram traces I get this result:

    image

    However, when I set the layout to Layout::new().bar_mode(BarMode::Overlay) I get:

    image

    The orange trace now uses fewer and wider bins? How do I change it to use the same bins as in the first example?

    Thanks, Wouter

    opened by wdecoster 0
  • Possibly redundant functionality

    Possibly redundant functionality

    A few days ago I wrote and released a crate featuring a yew component wrapper that uses your library. Now I noticed you also just recently extended the wasm support and added examples for yew.

    I wonder if it would make sense integrating this crate into your repo, or if we could move both repos to a joint github org?

    opened by butzist 2
  • Version 1.0 tracking issue

    Version 1.0 tracking issue

    This is a stub issue to track what is necessary to release a 1.0 version.

    I'll be adding to this over time to show what has been implemented and what still needs doing before we can call it a 1.0 release.

    Chart types

    Basic Charts

    • [x] Scatter
    • [x] Line
    • [x] Bar
    • [ ] Pie
    • [x] Bubble
    • [x] Dot
    • [ ] Filled area
    • [ ] Sunburst
    • [x] Sankey
    • [ ] Point Cloud
    • [ ] Treemaps
    • [ ] Tables

    Statistical Charts

    • [x] Box
    • [x] Histograms
    • [ ] 2D density
    • [ ] Violin
    • [ ] Parallel Categories
    • [ ] Splom

    Scientific Charts

    • [x] Contour
    • [x] Heatmaps
    • [ ] Ternary
    • [ ] Parallel Coordinates
    • [ ] Log
    • [x] Scatter polar
    • [ ] Bar polar
    • [ ] Carpet
    • [ ] Contour carpet

    Financial Charts

    • [ ] Waterfall
    • [ ] Indicator
    • [x] Candlestick
    • [ ] Funnel
    • [ ] Funnel area
    • [x] OHLC

    Maps

    • [ ] Density heatmap
    • [ ] Choropleth
    • [ ] Scatter geo
    • [x] Scatter mapbox

    3D Charts

    • [x] Scatter
    • [x] Surface
    • [x] Mesh
    • [ ] Cone
    • [ ] Streamtube
    • [ ] Isosurface

    API

    • [ ] Make the library panic-safe by replacing unwrap() and expect with Result (#33)

    Features

    • [x] Wasm support (complete as of v0.8.0)
    • [ ] Sliders

    Meta

    • [x] Add code coverage
    opened by mfreeborn 0
  • Animation support like for python

    Animation support like for python

    This is a feature request for supporting a animated plot like seen in this python example. I would expect it to work by giving for x and y a slice of slices or a slice of Vecs instead of a single slice. Given this python example:

    import plotly.express as px
    df = px.data.gapminder()
    px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
               size="pop", color="continent", hover_name="country",
               log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
    

    A usage example could look like the following code:

    use plotly::{common::Mode,Plot,Scatter};
    fn main() -> Result<(),BoxErr> {
        // Four different time points
        let time = vec![1.0,2.0,3.0,4.0]; 
        // For each timepoint generate data. This could be a position for example.
        let mut x = Vec::with_capacity(time.len());
        for i in 0..time.len() {
            x.push((0..1_000).map(|x|x as f64*0.1).collect::<Vec<f64>>());
        }
        // For each timepoint evaluate some function at each position
        let mut y = Vec::with_capacity(time.len());
        for (i,xi) in x.iter().enumerate() {
            y.push(
                xi.iter().map(|xk| xk*xk + time[i]).collect::<Vec<f64>>()
            );
        }
        // Generate traces from the data
        let traces = x.into_iter().zip(y).map(|(x,y)| Scatter::new(x,y).mode(Mode::Lines)).collect::<Vec<_>>();
        // Plot the data and animate the plot with respect to time
        let mut plot = Plot::new();
        plot.add_traces(traces).animate_by(time);
        plot.show();
        Ok(())
    }
    
    opened by Tastaturtaste 0
Releases(0.8.3)
Owner
Ioannis Giagkiozis
Ioannis Giagkiozis
A small charting/visualization tool and partial vega implementation for Rust

Gust A charting library for rust! Disclaimer This is still very much a work in progress! APIs are very unstable and subject to change. Contributions a

Samuel Resendez 128 Oct 14, 2022
Data plotting library for Rust

plotlib plotlib is a generic data visualisation and plotting library for Rust. It is currently in the very early stages of development. It can current

Matt Williams 411 Nov 26, 2022
A rust drawing library for high quality data plotting for both WASM and native, statically and realtimely 🦀 📈🚀

Plotters - A Rust drawing library focus on data plotting for both WASM and native applications ?? ?? ?? Plotters is drawing library designed for rende

Hao Hou 2.6k Dec 5, 2022
This is a Rust implementation of a boid flocking simulation using the ggez graphics crate.

Boidflock This is a Rust implementation of a boid flocking simulation using the ggez graphics crate. The CLI for this program is built using the struc

Andrew Lee 11 May 20, 2021
A Rust library for drawing plots, powered by Gnuplot.

RustGnuplot A Gnuplot controller written in Rust. Documentation See here Examples A simple example: let mut fg = Figure::new(); fg.axes2d() .set_titl

null 352 Nov 27, 2022
Swash is a pure Rust, cross-platform crate that provides font introspection, complex text shaping and glyph rendering.

Swash is a pure Rust, cross-platform crate that provides font introspection, complex text shaping and glyph rendering. Goals This crate aims to

Chad Brokaw 384 Nov 29, 2022
Render farm simulator & plotting for optimisation written in Rust.

Farm Usage Simulator Given a few basic charasteristics of a render farm and render jobs this app runs a few randomized farm usage scenarios and plots

ford 2 Jul 17, 2022
A pure Rust visualization library inspired by D3.js

charts A pure Rust visualization library inspired by D3.js. See gallery and examples for code and more charts. Install You can add this as a dependenc

Iulian Gulea 178 Nov 23, 2022
A Rust API for Vega-Lite V4 to build chart with a rusty API.

Vega-Lite V4 for Rust A Rust API for Vega-Lite V4 to build chart with a rusty API. Similar to the Altair project in python, this crate build upon Vega

Procyon 17 Sep 21, 2022
Rust crate for creating beautiful interactive Chord Diagrams

Chord PRO Released Chord PRO is the full-featured chord visualization API, producing beautiful interactive visualizations, e.g. those featured on the

Dr. Shahin Rostami 25 Sep 10, 2022
Externalize easily the plotting process from Rust to gnuplot.

preexplorer Easy plotter and saver of simple data. Handy tool for development stage or small computational projects. Save data, have a quick view and

Raimundo Saona 4 Jan 7, 2022
A library to generate syntax diagrams for Rust macros.

Live demo (code) A browser add-on for Firefox, Chrome and Edge A library to generate syntax ("railroad") diagrams for Rust's macro_rules!(). Diagrams

null 464 Nov 25, 2022
Graphical Rust program that uses a fractal algorithm to draw a tree of sorts

rusty-vegetation Graphical Rust program that uses a fractal algorithm to draw a "tree" of sorts. To Build and Run On Linux: Install build-essentials o

Stephen G Tuggy 3 Nov 5, 2022
A Rust program for visualizing how sections get packed into your Game Boy ROM

GB Packing Visualizer A Rust program for visualizing how sections get packed into your Game Boy ROM. rhythm_land.mp4 Each column represents a ROM bank

Eldred Habert 6 Jan 31, 2022
Lightweight graphs (sparklines) for use with Embedded Rust

Sparklines for Rust's Embedded-graphics Sparklines are small, high resolution graphics embedded in a context of words, numbers or images". Edward Tuft

Bernard Kobos 4 Aug 28, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 293 Sep 22, 2022
Slitter is a C- and Rust-callable slab allocator implemented primarily in Rust, with some C for performance or to avoid unstable Rust features.

Slitter is a less footgunny slab allocator Slitter is a classically structured thread-caching slab allocator that's meant to help write reliable long-

Backtrace Labs 134 Oct 11, 2022
First Git on Rust is reimplementation with rust in order to learn about rust, c and git.

First Git on Rust First Git on Rust is reimplementation with rust in order to learn about rust, c and git. Reference project This project refer to the

Nobkz 1 Jan 28, 2022
NES emulator written in Rust to learn Rust

OxideNES A NES emulator in Rust. CPU should be accurate, PPU is mostly accurate, timing between the 2 is off for some corner cases and hardware qui

null 37 Nov 7, 2022
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ A program that lists statistics related to the usage of unsafe Rust code in a Rust crate and all its dependencies. This cargo plugin w

Rust Secure Code Working Group 1.1k Nov 28, 2022