Axis

Struct Axis 

Source
pub struct Axis { /* private fields */ }
Expand description

A structure representing a customizable axis.

§Example

use polars::prelude::*;
use plotlars::{Axis, Plot, Rgb, ScatterPlot, Text, TickDirection};

let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
    .finish()
    .unwrap()
    .select([
        col("species"),
        col("sex").alias("gender"),
        col("flipper_length_mm").cast(DataType::Int16),
        col("body_mass_g").cast(DataType::Int16),
    ])
    .collect()
    .unwrap();

let axis = Axis::new()
    .show_line(true)
    .tick_direction(TickDirection::OutSide)
    .value_thousands(true)
    .show_grid(false);

ScatterPlot::builder()
    .data(&dataset)
    .x("body_mass_g")
    .y("flipper_length_mm")
    .group("species")
    .colors(vec![
        Rgb(255, 0, 0),
        Rgb(0, 255, 0),
        Rgb(0, 0, 255),
    ])
    .opacity(0.5)
    .size(20)
    .plot_title(
        Text::from("Scatter Plot")
            .font("Arial")
            .size(20)
            .x(0.045)
    )
    .x_title("body mass (g)")
    .y_title("flipper length (mm)")
    .legend_title("species")
    .x_axis(&axis)
    .y_axis(&axis)
    .build()
    .plot();

example

Implementations§

Source§

impl Axis

Source

pub fn new() -> Self

Creates a new Axis instance with default values.

Examples found in repository?
examples/image.rs (line 4)
3fn main() {
4    let axis = Axis::new().show_axis(false);
5
6    Image::builder()
7        .path("data/image.png")
8        .x_axis(&axis)
9        .y_axis(&axis)
10        .plot_title("Image Plot")
11        .build()
12        .plot();
13}
More examples
Hide additional examples
examples/histogram.rs (line 18)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .show_grid(true)
21        .value_thousands(true)
22        .tick_direction(TickDirection::OutSide);
23
24    Histogram::builder()
25        .data(&dataset)
26        .x("body_mass_g")
27        .group("species")
28        .opacity(0.5)
29        .colors(vec![Rgb(255, 165, 0), Rgb(147, 112, 219), Rgb(46, 139, 87)])
30        .plot_title(Text::from("Histogram").font("Arial").size(18))
31        .x_title(Text::from("body mass (g)").font("Arial").size(15))
32        .y_title(Text::from("count").font("Arial").size(15))
33        .legend_title(Text::from("species").font("Arial").size(15))
34        .x_axis(&axis)
35        .y_axis(&axis)
36        .legend(&Legend::new().x(0.9))
37        .build()
38        .plot();
39}
examples/boxplot.rs (line 33)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    BoxPlot::builder()
19        .data(&dataset)
20        .labels("species")
21        .values("body_mass_g")
22        .orientation(Orientation::Vertical)
23        .group("gender")
24        .box_points(true)
25        .point_offset(-1.5)
26        .jitter(0.01)
27        .opacity(0.1)
28        .colors(vec![Rgb(0, 191, 255), Rgb(57, 255, 20), Rgb(255, 105, 180)])
29        .plot_title(Text::from("Box Plot").font("Arial").size(18))
30        .x_title(Text::from("species").font("Arial").size(15))
31        .y_title(Text::from("body mass (g)").font("Arial").size(15))
32        .legend_title(Text::from("gender").font("Arial").size(15))
33        .y_axis(&Axis::new().value_thousands(true))
34        .legend(&Legend::new().border_width(1).x(0.9))
35        .build()
36        .plot();
37}
examples/scatterplot.rs (line 18)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .tick_direction(TickDirection::OutSide)
21        .value_thousands(true);
22
23    ScatterPlot::builder()
24        .data(&dataset)
25        .x("body_mass_g")
26        .y("flipper_length_mm")
27        .group("species")
28        .sort_groups_by(|a, b| {
29            if a.len() == b.len() {
30                a.cmp(b)
31            } else {
32                a.len().cmp(&b.len())
33            }
34        }) //sort by length unless equal length then lexical
35        .opacity(0.5)
36        .size(12)
37        .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
38        .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
39        .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
40        .x_title("body mass (g)")
41        .y_title("flipper length (mm)")
42        .legend_title("species")
43        .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
44        .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
45        .legend(&Legend::new().x(0.85).y(0.15))
46        .build()
47        .plot();
48}
examples/lineplot.rs (line 28)
6fn main() {
7    let x_values = Array::linspace(0.0, 2.0 * std::f64::consts::PI, 1000).to_vec();
8
9    let dataset = df![
10        "x" => &x_values,
11        "sine" => &x_values.iter().map(|arg0: &f64| f64::sin(*arg0)).collect::<Vec<_>>(),
12        "cosine" => &x_values.iter().map(|arg0: &f64| f64::cos(*arg0)).collect::<Vec<_>>(),
13    ]
14    .unwrap();
15
16    LinePlot::builder()
17        .data(&dataset)
18        .x("x")
19        .y("sine")
20        .additional_lines(vec!["cosine"])
21        .colors(vec![Rgb(255, 0, 0), Rgb(0, 255, 0)])
22        .lines(vec![Line::Solid, Line::Dot])
23        .width(3.0)
24        .with_shape(false)
25        .plot_title(Text::from("Line Plot").font("Arial").size(18))
26        .legend_title(Text::from("series").font("Arial").size(15))
27        .x_axis(
28            &Axis::new()
29                .tick_direction(TickDirection::OutSide)
30                .axis_position(0.5)
31                .tick_values(vec![
32                    0.5 * std::f64::consts::PI,
33                    std::f64::consts::PI,
34                    1.5 * std::f64::consts::PI,
35                    2.0 * std::f64::consts::PI,
36                ])
37                .tick_labels(vec!["π/2", "π", "3π/2", "2π"]),
38        )
39        .y_axis(
40            &Axis::new()
41                .tick_direction(TickDirection::OutSide)
42                .tick_values(vec![-1.0, 0.0, 1.0])
43                .tick_labels(vec!["-1", "0", "1"]),
44        )
45        .build()
46        .plot();
47}
examples/ohlc.rs (line 67)
4fn main() {
5    // Create sample OHLC data
6    let dates = vec![
7        "2024-01-01",
8        "2024-01-02",
9        "2024-01-03",
10        "2024-01-04",
11        "2024-01-05",
12        "2024-01-08",
13        "2024-01-09",
14        "2024-01-10",
15        "2024-01-11",
16        "2024-01-12",
17        "2024-01-15",
18        "2024-01-16",
19        "2024-01-17",
20        "2024-01-18",
21        "2024-01-19",
22        "2024-01-22",
23        "2024-01-23",
24        "2024-01-24",
25        "2024-01-25",
26        "2024-01-26",
27    ];
28
29    let open_prices = vec![
30        100.0, 102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5,
31        111.0, 112.5, 112.0, 113.5, 113.0, 114.5, 115.0,
32    ];
33
34    let high_prices = vec![
35        103.0, 104.0, 103.5, 106.0, 107.5, 107.0, 108.5, 108.0, 109.5, 111.0, 110.5, 112.5, 112.0,
36        113.5, 115.0, 114.5, 116.0, 115.5, 117.0, 117.5,
37    ];
38
39    let low_prices = vec![
40        99.0, 101.5, 100.0, 102.5, 104.0, 103.5, 105.0, 104.5, 106.0, 107.5, 107.0, 109.0, 108.5,
41        110.0, 111.5, 111.0, 112.5, 112.0, 113.5, 114.0,
42    ];
43
44    let close_prices = vec![
45        102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5, 111.0,
46        112.5, 112.0, 113.5, 113.0, 114.5, 115.0, 116.5,
47    ];
48
49    let stock_data = df! {
50        "date" => dates,
51        "open" => open_prices,
52        "high" => high_prices,
53        "low" => low_prices,
54        "close" => close_prices,
55    }
56    .unwrap();
57
58    OhlcPlot::builder()
59        .data(&stock_data)
60        .dates("date")
61        .open("open")
62        .high("high")
63        .low("low")
64        .close("close")
65        .plot_title("Stock Price")
66        .y_title("Price ($)")
67        .y_axis(&Axis::new().show_axis(true))
68        .build()
69        .plot();
70}
Source

pub fn show_axis(self, bool: bool) -> Self

Sets the visibility of the axis.

§Argument
  • bool - A boolean value indicating whether the axis should be visible.
Examples found in repository?
examples/image.rs (line 4)
3fn main() {
4    let axis = Axis::new().show_axis(false);
5
6    Image::builder()
7        .path("data/image.png")
8        .x_axis(&axis)
9        .y_axis(&axis)
10        .plot_title("Image Plot")
11        .build()
12        .plot();
13}
More examples
Hide additional examples
examples/ohlc.rs (line 67)
4fn main() {
5    // Create sample OHLC data
6    let dates = vec![
7        "2024-01-01",
8        "2024-01-02",
9        "2024-01-03",
10        "2024-01-04",
11        "2024-01-05",
12        "2024-01-08",
13        "2024-01-09",
14        "2024-01-10",
15        "2024-01-11",
16        "2024-01-12",
17        "2024-01-15",
18        "2024-01-16",
19        "2024-01-17",
20        "2024-01-18",
21        "2024-01-19",
22        "2024-01-22",
23        "2024-01-23",
24        "2024-01-24",
25        "2024-01-25",
26        "2024-01-26",
27    ];
28
29    let open_prices = vec![
30        100.0, 102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5,
31        111.0, 112.5, 112.0, 113.5, 113.0, 114.5, 115.0,
32    ];
33
34    let high_prices = vec![
35        103.0, 104.0, 103.5, 106.0, 107.5, 107.0, 108.5, 108.0, 109.5, 111.0, 110.5, 112.5, 112.0,
36        113.5, 115.0, 114.5, 116.0, 115.5, 117.0, 117.5,
37    ];
38
39    let low_prices = vec![
40        99.0, 101.5, 100.0, 102.5, 104.0, 103.5, 105.0, 104.5, 106.0, 107.5, 107.0, 109.0, 108.5,
41        110.0, 111.5, 111.0, 112.5, 112.0, 113.5, 114.0,
42    ];
43
44    let close_prices = vec![
45        102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5, 111.0,
46        112.5, 112.0, 113.5, 113.0, 114.5, 115.0, 116.5,
47    ];
48
49    let stock_data = df! {
50        "date" => dates,
51        "open" => open_prices,
52        "high" => high_prices,
53        "low" => low_prices,
54        "close" => close_prices,
55    }
56    .unwrap();
57
58    OhlcPlot::builder()
59        .data(&stock_data)
60        .dates("date")
61        .open("open")
62        .high("high")
63        .low("low")
64        .close("close")
65        .plot_title("Stock Price")
66        .y_title("Price ($)")
67        .y_axis(&Axis::new().show_axis(true))
68        .build()
69        .plot();
70}
examples/candlestick.rs (line 79)
4fn main() {
5    // Create sample candlestick data
6    let dates = vec![
7        "2024-01-01",
8        "2024-01-02",
9        "2024-01-03",
10        "2024-01-04",
11        "2024-01-05",
12        "2024-01-08",
13        "2024-01-09",
14        "2024-01-10",
15        "2024-01-11",
16        "2024-01-12",
17        "2024-01-15",
18        "2024-01-16",
19        "2024-01-17",
20        "2024-01-18",
21        "2024-01-19",
22        "2024-01-22",
23        "2024-01-23",
24        "2024-01-24",
25        "2024-01-25",
26        "2024-01-26",
27    ];
28
29    let open_prices = vec![
30        100.0, 102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5,
31        111.0, 112.5, 112.0, 113.5, 113.0, 114.5, 115.0,
32    ];
33
34    let high_prices = vec![
35        103.0, 104.0, 103.5, 106.0, 107.5, 107.0, 108.5, 108.0, 109.5, 111.0, 110.5, 112.5, 112.0,
36        113.5, 115.0, 114.5, 116.0, 115.5, 117.0, 117.5,
37    ];
38
39    let low_prices = vec![
40        99.0, 101.5, 100.0, 102.5, 104.0, 103.5, 105.0, 104.5, 106.0, 107.5, 107.0, 109.0, 108.5,
41        110.0, 111.5, 111.0, 112.5, 112.0, 113.5, 114.0,
42    ];
43
44    let close_prices = vec![
45        102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5, 111.0,
46        112.5, 112.0, 113.5, 113.0, 114.5, 115.0, 116.5,
47    ];
48
49    let stock_data = df! {
50        "date" => dates,
51        "open" => open_prices,
52        "high" => high_prices,
53        "low" => low_prices,
54        "close" => close_prices,
55    }
56    .unwrap();
57
58    // Candlestick chart with whisker width customization
59    let increasing = Direction::new()
60        .line_color(Rgb(0, 200, 100)) // Green
61        .line_width(0.5);
62
63    let decreasing = Direction::new()
64        .line_color(Rgb(200, 50, 50)) // Red
65        .line_width(0.5);
66
67    CandlestickPlot::builder()
68        .data(&stock_data)
69        .dates("date")
70        .open("open")
71        .high("high")
72        .low("low")
73        .close("close")
74        .increasing(&increasing)
75        .decreasing(&decreasing)
76        .whisker_width(0.1) // Thin whiskers
77        .plot_title("Stock Price - Thin Whiskers")
78        .y_title("Price ($)")
79        .y_axis(&Axis::new().show_axis(true).show_grid(true))
80        .build()
81        .plot();
82}
Source

pub fn axis_side(self, side: AxisSide) -> Self

Sets the side of the axis.

§Argument
  • side - An AxisSide enum value representing the side of the axis.
Examples found in repository?
examples/timeseriesplot.rs (line 41)
5fn main() {
6    // Example 1: Revenue and Cost with advanced styling
7    let revenue_dataset = LazyCsvReader::new(PlPath::new("data/revenue_and_cost.csv"))
8        .finish()
9        .unwrap()
10        .select([
11            col("Date").cast(DataType::String),
12            col("Revenue").cast(DataType::Int32),
13            col("Cost").cast(DataType::Int32),
14        ])
15        .collect()
16        .unwrap();
17
18    TimeSeriesPlot::builder()
19        .data(&revenue_dataset)
20        .x("Date")
21        .y("Revenue")
22        .additional_series(vec!["Cost"])
23        .size(8)
24        .colors(vec![Rgb(0, 0, 255), Rgb(255, 0, 0)])
25        .lines(vec![Line::Dash, Line::Solid])
26        .with_shape(true)
27        .shapes(vec![Shape::Circle, Shape::Square])
28        .plot_title(Text::from("Time Series Plot").font("Arial").size(18))
29        .legend(&Legend::new().x(0.05).y(0.9))
30        .x_title("x")
31        .y_title(Text::from("y").color(Rgb(0, 0, 255)))
32        .y_title2(Text::from("y2").color(Rgb(255, 0, 0)))
33        .y_axis(
34            &Axis::new()
35                .value_color(Rgb(0, 0, 255))
36                .show_grid(false)
37                .zero_line_color(Rgb(0, 0, 0)),
38        )
39        .y_axis2(
40            &Axis::new()
41                .axis_side(plotlars::AxisSide::Right)
42                .value_color(Rgb(255, 0, 0))
43                .show_grid(false),
44        )
45        .build()
46        .plot();
47
48    // Example 2: Temperature data with date parsing
49    let temperature_dataset = LazyCsvReader::new(PlPath::new("data/debilt_2023_temps.csv"))
50        .with_has_header(true)
51        .with_try_parse_dates(true)
52        .finish()
53        .unwrap()
54        .with_columns(vec![
55            (col("tavg") / lit(10)).alias("tavg"),
56            (col("tmin") / lit(10)).alias("tmin"),
57            (col("tmax") / lit(10)).alias("tmax"),
58        ])
59        .collect()
60        .unwrap();
61
62    TimeSeriesPlot::builder()
63        .data(&temperature_dataset)
64        .x("date")
65        .y("tavg")
66        .additional_series(vec!["tmin", "tmax"])
67        .colors(vec![Rgb(128, 128, 128), Rgb(0, 122, 255), Rgb(255, 128, 0)])
68        .lines(vec![Line::Solid, Line::Dot, Line::Dot])
69        .plot_title("Temperature at De Bilt (2023)")
70        .legend_title("Legend")
71        .build()
72        .plot();
73}
Source

pub fn axis_position(self, position: f64) -> Self

Sets the position of the axis.

§Argument
  • position - A f64 value representing the position of the axis.
Examples found in repository?
examples/lineplot.rs (line 30)
6fn main() {
7    let x_values = Array::linspace(0.0, 2.0 * std::f64::consts::PI, 1000).to_vec();
8
9    let dataset = df![
10        "x" => &x_values,
11        "sine" => &x_values.iter().map(|arg0: &f64| f64::sin(*arg0)).collect::<Vec<_>>(),
12        "cosine" => &x_values.iter().map(|arg0: &f64| f64::cos(*arg0)).collect::<Vec<_>>(),
13    ]
14    .unwrap();
15
16    LinePlot::builder()
17        .data(&dataset)
18        .x("x")
19        .y("sine")
20        .additional_lines(vec!["cosine"])
21        .colors(vec![Rgb(255, 0, 0), Rgb(0, 255, 0)])
22        .lines(vec![Line::Solid, Line::Dot])
23        .width(3.0)
24        .with_shape(false)
25        .plot_title(Text::from("Line Plot").font("Arial").size(18))
26        .legend_title(Text::from("series").font("Arial").size(15))
27        .x_axis(
28            &Axis::new()
29                .tick_direction(TickDirection::OutSide)
30                .axis_position(0.5)
31                .tick_values(vec![
32                    0.5 * std::f64::consts::PI,
33                    std::f64::consts::PI,
34                    1.5 * std::f64::consts::PI,
35                    2.0 * std::f64::consts::PI,
36                ])
37                .tick_labels(vec!["π/2", "π", "3π/2", "2π"]),
38        )
39        .y_axis(
40            &Axis::new()
41                .tick_direction(TickDirection::OutSide)
42                .tick_values(vec![-1.0, 0.0, 1.0])
43                .tick_labels(vec!["-1", "0", "1"]),
44        )
45        .build()
46        .plot();
47}
Source

pub fn axis_type(self, axis_type: AxisType) -> Self

Sets the type of the axis.

§Argument
  • axis_type - An AxisType enum value representing the type of the axis.
Source

pub fn value_color(self, color: Rgb) -> Self

Sets the color of the axis values.

§Argument
  • color - An Rgb struct representing the color of the axis values.
Examples found in repository?
examples/timeseriesplot.rs (line 35)
5fn main() {
6    // Example 1: Revenue and Cost with advanced styling
7    let revenue_dataset = LazyCsvReader::new(PlPath::new("data/revenue_and_cost.csv"))
8        .finish()
9        .unwrap()
10        .select([
11            col("Date").cast(DataType::String),
12            col("Revenue").cast(DataType::Int32),
13            col("Cost").cast(DataType::Int32),
14        ])
15        .collect()
16        .unwrap();
17
18    TimeSeriesPlot::builder()
19        .data(&revenue_dataset)
20        .x("Date")
21        .y("Revenue")
22        .additional_series(vec!["Cost"])
23        .size(8)
24        .colors(vec![Rgb(0, 0, 255), Rgb(255, 0, 0)])
25        .lines(vec![Line::Dash, Line::Solid])
26        .with_shape(true)
27        .shapes(vec![Shape::Circle, Shape::Square])
28        .plot_title(Text::from("Time Series Plot").font("Arial").size(18))
29        .legend(&Legend::new().x(0.05).y(0.9))
30        .x_title("x")
31        .y_title(Text::from("y").color(Rgb(0, 0, 255)))
32        .y_title2(Text::from("y2").color(Rgb(255, 0, 0)))
33        .y_axis(
34            &Axis::new()
35                .value_color(Rgb(0, 0, 255))
36                .show_grid(false)
37                .zero_line_color(Rgb(0, 0, 0)),
38        )
39        .y_axis2(
40            &Axis::new()
41                .axis_side(plotlars::AxisSide::Right)
42                .value_color(Rgb(255, 0, 0))
43                .show_grid(false),
44        )
45        .build()
46        .plot();
47
48    // Example 2: Temperature data with date parsing
49    let temperature_dataset = LazyCsvReader::new(PlPath::new("data/debilt_2023_temps.csv"))
50        .with_has_header(true)
51        .with_try_parse_dates(true)
52        .finish()
53        .unwrap()
54        .with_columns(vec![
55            (col("tavg") / lit(10)).alias("tavg"),
56            (col("tmin") / lit(10)).alias("tmin"),
57            (col("tmax") / lit(10)).alias("tmax"),
58        ])
59        .collect()
60        .unwrap();
61
62    TimeSeriesPlot::builder()
63        .data(&temperature_dataset)
64        .x("date")
65        .y("tavg")
66        .additional_series(vec!["tmin", "tmax"])
67        .colors(vec![Rgb(128, 128, 128), Rgb(0, 122, 255), Rgb(255, 128, 0)])
68        .lines(vec![Line::Solid, Line::Dot, Line::Dot])
69        .plot_title("Temperature at De Bilt (2023)")
70        .legend_title("Legend")
71        .build()
72        .plot();
73}
Source

pub fn value_range(self, range: Vec<f64>) -> Self

Sets the range of values displayed on the axis.

§Argument
  • range - A vector of f64 values representing the range of the axis.
Examples found in repository?
examples/scatterplot.rs (line 43)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .tick_direction(TickDirection::OutSide)
21        .value_thousands(true);
22
23    ScatterPlot::builder()
24        .data(&dataset)
25        .x("body_mass_g")
26        .y("flipper_length_mm")
27        .group("species")
28        .sort_groups_by(|a, b| {
29            if a.len() == b.len() {
30                a.cmp(b)
31            } else {
32                a.len().cmp(&b.len())
33            }
34        }) //sort by length unless equal length then lexical
35        .opacity(0.5)
36        .size(12)
37        .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
38        .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
39        .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
40        .x_title("body mass (g)")
41        .y_title("flipper length (mm)")
42        .legend_title("species")
43        .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
44        .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
45        .legend(&Legend::new().x(0.85).y(0.15))
46        .build()
47        .plot();
48}
Source

pub fn value_thousands(self, bool: bool) -> Self

Sets whether to use thousands separators for values.

§Argument
  • bool - A boolean value indicating whether to use thousands separators.
Examples found in repository?
examples/histogram.rs (line 21)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .show_grid(true)
21        .value_thousands(true)
22        .tick_direction(TickDirection::OutSide);
23
24    Histogram::builder()
25        .data(&dataset)
26        .x("body_mass_g")
27        .group("species")
28        .opacity(0.5)
29        .colors(vec![Rgb(255, 165, 0), Rgb(147, 112, 219), Rgb(46, 139, 87)])
30        .plot_title(Text::from("Histogram").font("Arial").size(18))
31        .x_title(Text::from("body mass (g)").font("Arial").size(15))
32        .y_title(Text::from("count").font("Arial").size(15))
33        .legend_title(Text::from("species").font("Arial").size(15))
34        .x_axis(&axis)
35        .y_axis(&axis)
36        .legend(&Legend::new().x(0.9))
37        .build()
38        .plot();
39}
More examples
Hide additional examples
examples/boxplot.rs (line 33)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    BoxPlot::builder()
19        .data(&dataset)
20        .labels("species")
21        .values("body_mass_g")
22        .orientation(Orientation::Vertical)
23        .group("gender")
24        .box_points(true)
25        .point_offset(-1.5)
26        .jitter(0.01)
27        .opacity(0.1)
28        .colors(vec![Rgb(0, 191, 255), Rgb(57, 255, 20), Rgb(255, 105, 180)])
29        .plot_title(Text::from("Box Plot").font("Arial").size(18))
30        .x_title(Text::from("species").font("Arial").size(15))
31        .y_title(Text::from("body mass (g)").font("Arial").size(15))
32        .legend_title(Text::from("gender").font("Arial").size(15))
33        .y_axis(&Axis::new().value_thousands(true))
34        .legend(&Legend::new().border_width(1).x(0.9))
35        .build()
36        .plot();
37}
examples/scatterplot.rs (line 21)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .tick_direction(TickDirection::OutSide)
21        .value_thousands(true);
22
23    ScatterPlot::builder()
24        .data(&dataset)
25        .x("body_mass_g")
26        .y("flipper_length_mm")
27        .group("species")
28        .sort_groups_by(|a, b| {
29            if a.len() == b.len() {
30                a.cmp(b)
31            } else {
32                a.len().cmp(&b.len())
33            }
34        }) //sort by length unless equal length then lexical
35        .opacity(0.5)
36        .size(12)
37        .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
38        .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
39        .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
40        .x_title("body mass (g)")
41        .y_title("flipper length (mm)")
42        .legend_title("species")
43        .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
44        .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
45        .legend(&Legend::new().x(0.85).y(0.15))
46        .build()
47        .plot();
48}
Source

pub fn value_exponent(self, exponent: ValueExponent) -> Self

Sets the exponent format for values on the axis.

§Argument
  • exponent - A ValueExponent enum value representing the exponent format.
Source

pub fn tick_values(self, values: Vec<f64>) -> Self

Sets the tick values for the axis.

§Argument
  • values - A vector of f64 values representing the tick values.
Examples found in repository?
examples/lineplot.rs (lines 31-36)
6fn main() {
7    let x_values = Array::linspace(0.0, 2.0 * std::f64::consts::PI, 1000).to_vec();
8
9    let dataset = df![
10        "x" => &x_values,
11        "sine" => &x_values.iter().map(|arg0: &f64| f64::sin(*arg0)).collect::<Vec<_>>(),
12        "cosine" => &x_values.iter().map(|arg0: &f64| f64::cos(*arg0)).collect::<Vec<_>>(),
13    ]
14    .unwrap();
15
16    LinePlot::builder()
17        .data(&dataset)
18        .x("x")
19        .y("sine")
20        .additional_lines(vec!["cosine"])
21        .colors(vec![Rgb(255, 0, 0), Rgb(0, 255, 0)])
22        .lines(vec![Line::Solid, Line::Dot])
23        .width(3.0)
24        .with_shape(false)
25        .plot_title(Text::from("Line Plot").font("Arial").size(18))
26        .legend_title(Text::from("series").font("Arial").size(15))
27        .x_axis(
28            &Axis::new()
29                .tick_direction(TickDirection::OutSide)
30                .axis_position(0.5)
31                .tick_values(vec![
32                    0.5 * std::f64::consts::PI,
33                    std::f64::consts::PI,
34                    1.5 * std::f64::consts::PI,
35                    2.0 * std::f64::consts::PI,
36                ])
37                .tick_labels(vec!["π/2", "π", "3π/2", "2π"]),
38        )
39        .y_axis(
40            &Axis::new()
41                .tick_direction(TickDirection::OutSide)
42                .tick_values(vec![-1.0, 0.0, 1.0])
43                .tick_labels(vec!["-1", "0", "1"]),
44        )
45        .build()
46        .plot();
47}
Source

pub fn tick_labels(self, labels: Vec<impl Into<String>>) -> Self

Sets the tick labels for the axis.

§Argument
  • labels - A vector of values that can be converted into String, representing the tick labels.
Examples found in repository?
examples/lineplot.rs (line 37)
6fn main() {
7    let x_values = Array::linspace(0.0, 2.0 * std::f64::consts::PI, 1000).to_vec();
8
9    let dataset = df![
10        "x" => &x_values,
11        "sine" => &x_values.iter().map(|arg0: &f64| f64::sin(*arg0)).collect::<Vec<_>>(),
12        "cosine" => &x_values.iter().map(|arg0: &f64| f64::cos(*arg0)).collect::<Vec<_>>(),
13    ]
14    .unwrap();
15
16    LinePlot::builder()
17        .data(&dataset)
18        .x("x")
19        .y("sine")
20        .additional_lines(vec!["cosine"])
21        .colors(vec![Rgb(255, 0, 0), Rgb(0, 255, 0)])
22        .lines(vec![Line::Solid, Line::Dot])
23        .width(3.0)
24        .with_shape(false)
25        .plot_title(Text::from("Line Plot").font("Arial").size(18))
26        .legend_title(Text::from("series").font("Arial").size(15))
27        .x_axis(
28            &Axis::new()
29                .tick_direction(TickDirection::OutSide)
30                .axis_position(0.5)
31                .tick_values(vec![
32                    0.5 * std::f64::consts::PI,
33                    std::f64::consts::PI,
34                    1.5 * std::f64::consts::PI,
35                    2.0 * std::f64::consts::PI,
36                ])
37                .tick_labels(vec!["π/2", "π", "3π/2", "2π"]),
38        )
39        .y_axis(
40            &Axis::new()
41                .tick_direction(TickDirection::OutSide)
42                .tick_values(vec![-1.0, 0.0, 1.0])
43                .tick_labels(vec!["-1", "0", "1"]),
44        )
45        .build()
46        .plot();
47}
Source

pub fn tick_direction(self, direction: TickDirection) -> Self

Sets the direction of the axis ticks.

§Argument
  • direction - A TickDirection enum value representing the direction of the ticks.
Examples found in repository?
examples/histogram.rs (line 22)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .show_grid(true)
21        .value_thousands(true)
22        .tick_direction(TickDirection::OutSide);
23
24    Histogram::builder()
25        .data(&dataset)
26        .x("body_mass_g")
27        .group("species")
28        .opacity(0.5)
29        .colors(vec![Rgb(255, 165, 0), Rgb(147, 112, 219), Rgb(46, 139, 87)])
30        .plot_title(Text::from("Histogram").font("Arial").size(18))
31        .x_title(Text::from("body mass (g)").font("Arial").size(15))
32        .y_title(Text::from("count").font("Arial").size(15))
33        .legend_title(Text::from("species").font("Arial").size(15))
34        .x_axis(&axis)
35        .y_axis(&axis)
36        .legend(&Legend::new().x(0.9))
37        .build()
38        .plot();
39}
More examples
Hide additional examples
examples/scatterplot.rs (line 20)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .tick_direction(TickDirection::OutSide)
21        .value_thousands(true);
22
23    ScatterPlot::builder()
24        .data(&dataset)
25        .x("body_mass_g")
26        .y("flipper_length_mm")
27        .group("species")
28        .sort_groups_by(|a, b| {
29            if a.len() == b.len() {
30                a.cmp(b)
31            } else {
32                a.len().cmp(&b.len())
33            }
34        }) //sort by length unless equal length then lexical
35        .opacity(0.5)
36        .size(12)
37        .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
38        .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
39        .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
40        .x_title("body mass (g)")
41        .y_title("flipper length (mm)")
42        .legend_title("species")
43        .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
44        .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
45        .legend(&Legend::new().x(0.85).y(0.15))
46        .build()
47        .plot();
48}
examples/lineplot.rs (line 29)
6fn main() {
7    let x_values = Array::linspace(0.0, 2.0 * std::f64::consts::PI, 1000).to_vec();
8
9    let dataset = df![
10        "x" => &x_values,
11        "sine" => &x_values.iter().map(|arg0: &f64| f64::sin(*arg0)).collect::<Vec<_>>(),
12        "cosine" => &x_values.iter().map(|arg0: &f64| f64::cos(*arg0)).collect::<Vec<_>>(),
13    ]
14    .unwrap();
15
16    LinePlot::builder()
17        .data(&dataset)
18        .x("x")
19        .y("sine")
20        .additional_lines(vec!["cosine"])
21        .colors(vec![Rgb(255, 0, 0), Rgb(0, 255, 0)])
22        .lines(vec![Line::Solid, Line::Dot])
23        .width(3.0)
24        .with_shape(false)
25        .plot_title(Text::from("Line Plot").font("Arial").size(18))
26        .legend_title(Text::from("series").font("Arial").size(15))
27        .x_axis(
28            &Axis::new()
29                .tick_direction(TickDirection::OutSide)
30                .axis_position(0.5)
31                .tick_values(vec![
32                    0.5 * std::f64::consts::PI,
33                    std::f64::consts::PI,
34                    1.5 * std::f64::consts::PI,
35                    2.0 * std::f64::consts::PI,
36                ])
37                .tick_labels(vec!["π/2", "π", "3π/2", "2π"]),
38        )
39        .y_axis(
40            &Axis::new()
41                .tick_direction(TickDirection::OutSide)
42                .tick_values(vec![-1.0, 0.0, 1.0])
43                .tick_labels(vec!["-1", "0", "1"]),
44        )
45        .build()
46        .plot();
47}
Source

pub fn tick_length(self, length: usize) -> Self

Sets the length of the axis ticks.

§Argument
  • length - A usize value representing the length of the ticks.
Source

pub fn tick_width(self, width: usize) -> Self

Sets the width of the axis ticks.

§Argument
  • width - A usize value representing the width of the ticks.
Source

pub fn tick_color(self, color: Rgb) -> Self

Sets the color of the axis ticks.

§Argument
  • color - An Rgb struct representing the color of the ticks.
Source

pub fn tick_angle(self, angle: f64) -> Self

Sets the angle of the axis ticks.

§Argument
  • angle - A f64 value representing the angle of the ticks in degrees.
Source

pub fn tick_font(self, font: impl Into<String>) -> Self

Sets the font of the axis tick labels.

§Argument
  • font - A value that can be converted into a String, representing the font name for the tick labels.
Source

pub fn show_line(self, bool: bool) -> Self

Sets whether to show the axis line.

§Argument
  • bool - A boolean value indicating whether the axis line should be visible.
Examples found in repository?
examples/histogram.rs (line 19)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .show_grid(true)
21        .value_thousands(true)
22        .tick_direction(TickDirection::OutSide);
23
24    Histogram::builder()
25        .data(&dataset)
26        .x("body_mass_g")
27        .group("species")
28        .opacity(0.5)
29        .colors(vec![Rgb(255, 165, 0), Rgb(147, 112, 219), Rgb(46, 139, 87)])
30        .plot_title(Text::from("Histogram").font("Arial").size(18))
31        .x_title(Text::from("body mass (g)").font("Arial").size(15))
32        .y_title(Text::from("count").font("Arial").size(15))
33        .legend_title(Text::from("species").font("Arial").size(15))
34        .x_axis(&axis)
35        .y_axis(&axis)
36        .legend(&Legend::new().x(0.9))
37        .build()
38        .plot();
39}
More examples
Hide additional examples
examples/scatterplot.rs (line 19)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .tick_direction(TickDirection::OutSide)
21        .value_thousands(true);
22
23    ScatterPlot::builder()
24        .data(&dataset)
25        .x("body_mass_g")
26        .y("flipper_length_mm")
27        .group("species")
28        .sort_groups_by(|a, b| {
29            if a.len() == b.len() {
30                a.cmp(b)
31            } else {
32                a.len().cmp(&b.len())
33            }
34        }) //sort by length unless equal length then lexical
35        .opacity(0.5)
36        .size(12)
37        .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
38        .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
39        .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
40        .x_title("body mass (g)")
41        .y_title("flipper length (mm)")
42        .legend_title("species")
43        .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
44        .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
45        .legend(&Legend::new().x(0.85).y(0.15))
46        .build()
47        .plot();
48}
Source

pub fn line_color(self, color: Rgb) -> Self

Sets the color of the axis line.

§Argument
  • color - An Rgb struct representing the color of the axis line.
Source

pub fn line_width(self, width: usize) -> Self

Sets the width of the axis line.

§Argument
  • width - A usize value representing the width of the axis line.
Source

pub fn show_grid(self, bool: bool) -> Self

Sets whether to show the grid lines on the axis.

§Argument
  • bool - A boolean value indicating whether the grid lines should be visible.
Examples found in repository?
examples/histogram.rs (line 20)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([
10            col("species"),
11            col("sex").alias("gender"),
12            col("flipper_length_mm").cast(DataType::Int16),
13            col("body_mass_g").cast(DataType::Int16),
14        ])
15        .collect()
16        .unwrap();
17
18    let axis = Axis::new()
19        .show_line(true)
20        .show_grid(true)
21        .value_thousands(true)
22        .tick_direction(TickDirection::OutSide);
23
24    Histogram::builder()
25        .data(&dataset)
26        .x("body_mass_g")
27        .group("species")
28        .opacity(0.5)
29        .colors(vec![Rgb(255, 165, 0), Rgb(147, 112, 219), Rgb(46, 139, 87)])
30        .plot_title(Text::from("Histogram").font("Arial").size(18))
31        .x_title(Text::from("body mass (g)").font("Arial").size(15))
32        .y_title(Text::from("count").font("Arial").size(15))
33        .legend_title(Text::from("species").font("Arial").size(15))
34        .x_axis(&axis)
35        .y_axis(&axis)
36        .legend(&Legend::new().x(0.9))
37        .build()
38        .plot();
39}
More examples
Hide additional examples
examples/candlestick.rs (line 79)
4fn main() {
5    // Create sample candlestick data
6    let dates = vec![
7        "2024-01-01",
8        "2024-01-02",
9        "2024-01-03",
10        "2024-01-04",
11        "2024-01-05",
12        "2024-01-08",
13        "2024-01-09",
14        "2024-01-10",
15        "2024-01-11",
16        "2024-01-12",
17        "2024-01-15",
18        "2024-01-16",
19        "2024-01-17",
20        "2024-01-18",
21        "2024-01-19",
22        "2024-01-22",
23        "2024-01-23",
24        "2024-01-24",
25        "2024-01-25",
26        "2024-01-26",
27    ];
28
29    let open_prices = vec![
30        100.0, 102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5,
31        111.0, 112.5, 112.0, 113.5, 113.0, 114.5, 115.0,
32    ];
33
34    let high_prices = vec![
35        103.0, 104.0, 103.5, 106.0, 107.5, 107.0, 108.5, 108.0, 109.5, 111.0, 110.5, 112.5, 112.0,
36        113.5, 115.0, 114.5, 116.0, 115.5, 117.0, 117.5,
37    ];
38
39    let low_prices = vec![
40        99.0, 101.5, 100.0, 102.5, 104.0, 103.5, 105.0, 104.5, 106.0, 107.5, 107.0, 109.0, 108.5,
41        110.0, 111.5, 111.0, 112.5, 112.0, 113.5, 114.0,
42    ];
43
44    let close_prices = vec![
45        102.5, 101.0, 103.5, 105.0, 104.5, 106.0, 105.5, 107.0, 108.5, 108.0, 110.0, 109.5, 111.0,
46        112.5, 112.0, 113.5, 113.0, 114.5, 115.0, 116.5,
47    ];
48
49    let stock_data = df! {
50        "date" => dates,
51        "open" => open_prices,
52        "high" => high_prices,
53        "low" => low_prices,
54        "close" => close_prices,
55    }
56    .unwrap();
57
58    // Candlestick chart with whisker width customization
59    let increasing = Direction::new()
60        .line_color(Rgb(0, 200, 100)) // Green
61        .line_width(0.5);
62
63    let decreasing = Direction::new()
64        .line_color(Rgb(200, 50, 50)) // Red
65        .line_width(0.5);
66
67    CandlestickPlot::builder()
68        .data(&stock_data)
69        .dates("date")
70        .open("open")
71        .high("high")
72        .low("low")
73        .close("close")
74        .increasing(&increasing)
75        .decreasing(&decreasing)
76        .whisker_width(0.1) // Thin whiskers
77        .plot_title("Stock Price - Thin Whiskers")
78        .y_title("Price ($)")
79        .y_axis(&Axis::new().show_axis(true).show_grid(true))
80        .build()
81        .plot();
82}
examples/timeseriesplot.rs (line 36)
5fn main() {
6    // Example 1: Revenue and Cost with advanced styling
7    let revenue_dataset = LazyCsvReader::new(PlPath::new("data/revenue_and_cost.csv"))
8        .finish()
9        .unwrap()
10        .select([
11            col("Date").cast(DataType::String),
12            col("Revenue").cast(DataType::Int32),
13            col("Cost").cast(DataType::Int32),
14        ])
15        .collect()
16        .unwrap();
17
18    TimeSeriesPlot::builder()
19        .data(&revenue_dataset)
20        .x("Date")
21        .y("Revenue")
22        .additional_series(vec!["Cost"])
23        .size(8)
24        .colors(vec![Rgb(0, 0, 255), Rgb(255, 0, 0)])
25        .lines(vec![Line::Dash, Line::Solid])
26        .with_shape(true)
27        .shapes(vec![Shape::Circle, Shape::Square])
28        .plot_title(Text::from("Time Series Plot").font("Arial").size(18))
29        .legend(&Legend::new().x(0.05).y(0.9))
30        .x_title("x")
31        .y_title(Text::from("y").color(Rgb(0, 0, 255)))
32        .y_title2(Text::from("y2").color(Rgb(255, 0, 0)))
33        .y_axis(
34            &Axis::new()
35                .value_color(Rgb(0, 0, 255))
36                .show_grid(false)
37                .zero_line_color(Rgb(0, 0, 0)),
38        )
39        .y_axis2(
40            &Axis::new()
41                .axis_side(plotlars::AxisSide::Right)
42                .value_color(Rgb(255, 0, 0))
43                .show_grid(false),
44        )
45        .build()
46        .plot();
47
48    // Example 2: Temperature data with date parsing
49    let temperature_dataset = LazyCsvReader::new(PlPath::new("data/debilt_2023_temps.csv"))
50        .with_has_header(true)
51        .with_try_parse_dates(true)
52        .finish()
53        .unwrap()
54        .with_columns(vec![
55            (col("tavg") / lit(10)).alias("tavg"),
56            (col("tmin") / lit(10)).alias("tmin"),
57            (col("tmax") / lit(10)).alias("tmax"),
58        ])
59        .collect()
60        .unwrap();
61
62    TimeSeriesPlot::builder()
63        .data(&temperature_dataset)
64        .x("date")
65        .y("tavg")
66        .additional_series(vec!["tmin", "tmax"])
67        .colors(vec![Rgb(128, 128, 128), Rgb(0, 122, 255), Rgb(255, 128, 0)])
68        .lines(vec![Line::Solid, Line::Dot, Line::Dot])
69        .plot_title("Temperature at De Bilt (2023)")
70        .legend_title("Legend")
71        .build()
72        .plot();
73}
Source

pub fn grid_color(self, color: Rgb) -> Self

Sets the color of the grid lines on the axis.

§Argument
  • color - An Rgb struct representing the color of the grid lines.
Source

pub fn grid_width(self, width: usize) -> Self

Sets the width of the grid lines on the axis.

§Argument
  • width - A usize value representing the width of the grid lines.
Source

pub fn show_zero_line(self, bool: bool) -> Self

Sets whether to show the zero line on the axis.

§Argument
  • bool - A boolean value indicating whether the zero line should be visible.
Source

pub fn zero_line_color(self, color: Rgb) -> Self

Sets the color of the zero line on the axis.

§Argument
  • color - An Rgb struct representing the color of the zero line.
Examples found in repository?
examples/timeseriesplot.rs (line 37)
5fn main() {
6    // Example 1: Revenue and Cost with advanced styling
7    let revenue_dataset = LazyCsvReader::new(PlPath::new("data/revenue_and_cost.csv"))
8        .finish()
9        .unwrap()
10        .select([
11            col("Date").cast(DataType::String),
12            col("Revenue").cast(DataType::Int32),
13            col("Cost").cast(DataType::Int32),
14        ])
15        .collect()
16        .unwrap();
17
18    TimeSeriesPlot::builder()
19        .data(&revenue_dataset)
20        .x("Date")
21        .y("Revenue")
22        .additional_series(vec!["Cost"])
23        .size(8)
24        .colors(vec![Rgb(0, 0, 255), Rgb(255, 0, 0)])
25        .lines(vec![Line::Dash, Line::Solid])
26        .with_shape(true)
27        .shapes(vec![Shape::Circle, Shape::Square])
28        .plot_title(Text::from("Time Series Plot").font("Arial").size(18))
29        .legend(&Legend::new().x(0.05).y(0.9))
30        .x_title("x")
31        .y_title(Text::from("y").color(Rgb(0, 0, 255)))
32        .y_title2(Text::from("y2").color(Rgb(255, 0, 0)))
33        .y_axis(
34            &Axis::new()
35                .value_color(Rgb(0, 0, 255))
36                .show_grid(false)
37                .zero_line_color(Rgb(0, 0, 0)),
38        )
39        .y_axis2(
40            &Axis::new()
41                .axis_side(plotlars::AxisSide::Right)
42                .value_color(Rgb(255, 0, 0))
43                .show_grid(false),
44        )
45        .build()
46        .plot();
47
48    // Example 2: Temperature data with date parsing
49    let temperature_dataset = LazyCsvReader::new(PlPath::new("data/debilt_2023_temps.csv"))
50        .with_has_header(true)
51        .with_try_parse_dates(true)
52        .finish()
53        .unwrap()
54        .with_columns(vec![
55            (col("tavg") / lit(10)).alias("tavg"),
56            (col("tmin") / lit(10)).alias("tmin"),
57            (col("tmax") / lit(10)).alias("tmax"),
58        ])
59        .collect()
60        .unwrap();
61
62    TimeSeriesPlot::builder()
63        .data(&temperature_dataset)
64        .x("date")
65        .y("tavg")
66        .additional_series(vec!["tmin", "tmax"])
67        .colors(vec![Rgb(128, 128, 128), Rgb(0, 122, 255), Rgb(255, 128, 0)])
68        .lines(vec![Line::Solid, Line::Dot, Line::Dot])
69        .plot_title("Temperature at De Bilt (2023)")
70        .legend_title("Legend")
71        .build()
72        .plot();
73}
Source

pub fn zero_line_width(self, width: usize) -> Self

Sets the width of the zero line on the axis.

§Argument
  • width - A usize value representing the width of the zero line.

Trait Implementations§

Source§

impl Clone for Axis

Source§

fn clone(&self) -> Axis

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Axis

Source§

fn default() -> Axis

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Axis

§

impl RefUnwindSafe for Axis

§

impl Send for Axis

§

impl Sync for Axis

§

impl Unpin for Axis

§

impl UnwindSafe for Axis

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T