plotiron/
lib.rs

1//! PlotIron - A Rust plotting library inspired by matplotlib
2//!
3//! This library provides a simple and intuitive API for creating 2D plots
4//! similar to matplotlib in Python.
5
6pub mod axes;
7pub mod colors;
8pub mod dot;
9pub mod figure;
10pub mod markers;
11pub mod plot;
12pub mod prelude;
13pub mod utils;
14pub mod viewer;
15
16pub use axes::Axes;
17pub use colors::Color;
18pub use figure::Figure;
19pub use markers::Marker;
20pub use plot::{Plot, PlotType};
21
22/// Trait for types that can be converted into Vec<f64>
23pub trait IntoVec<T> {
24    fn into_vec(self) -> Vec<T>;
25}
26
27impl<T, Tp> IntoVec<T> for Tp
28where
29    Tp: Into<Vec<T>>,
30{
31    fn into_vec(self) -> Vec<T> {
32        self.into()
33    }
34}
35
36/// Create a new figure with default settings
37pub fn figure() -> Figure {
38    Figure::new()
39}
40
41/// Create a new figure with specified width and height
42pub fn figure_with_size(width: f64, height: f64) -> Figure {
43    Figure::with_size(width, height)
44}
45
46/// Quick plot function for simple line plots
47pub fn plot(x: &[f64], y: &[f64]) -> Figure {
48    let mut fig = Figure::new();
49    fig.add_subplot().plot(x, y);
50    fig
51}
52
53/// Quick scatter plot function
54pub fn scatter(x: &[f64], y: &[f64]) -> Figure {
55    let mut fig = Figure::new();
56    fig.add_subplot().scatter(x, y);
57    fig
58}