rtplot

Crates.iortplot
lib.rsrtplot
version0.2.0
sourcesrc
created_at2019-09-17 20:10:31.132715
updated_at2021-04-27 00:30:48.401175
descriptionA library for generating plots of real-time data.
homepagehttps://github.com/ostrosco/rtplot
repositoryhttps://github.com/ostrosco/rtplot
max_upload_size
id165538
size66,146
(ostrosco)

documentation

README

rtplot

A library for doing real-time plotting in Rust. This is still in its early stages of development, so expect the API change and improve over time.

Usage:

Usage of the library requires two steps: configuring the plot and displaying the plot with its rendering function.

use rand_distr::{Distribution, Normal};
use rtplot::{Figure, PlotType};

fn main() {
    let normal = Normal::new(0.0, 1.0).unwrap();
    let mut rng = rand::thread_rng();
    // Configure the plot to hold 100 samples at a time. The x axis is not
    // specified, so it is dynamically updated at runtime.
    let mut figure = Figure::new(100)
        .ylim([-1.0, 1.0])
        .xlabel("Time (s)")
        .ylabel("Amplitude")
        .plot_type(PlotType::Line)
        .color(0x80, 0x00, 0x80);

    // The closure is called every time to generate a new state for the plot.
    // The figure _must_ be run on the main thread due to compatibility issues
    // with events loops on non-Unix operatins sytems.
    Figure::display(&mut figure, |fig| {
        let v: Vec<f32> = normal
            .sample_iter(&mut rng)
            .take(10)
            .map(|x| x as f32)
            .collect();
        fig.plot_stream(&v);
    });
}
Commit count: 67

cargo fmt