Skip to content

Animation support like for python #58

@Tastaturtaste

Description

@Tastaturtaste

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(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions