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();
Implementations§
Source§impl Axis
impl Axis
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Axis instance with default values.
Examples found in repository?
More examples
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}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}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| if a.len() == b.len() { a.cmp(b) } else { a.len().cmp(&b.len()) }) //sort by length unless equal length then lexical
29 .opacity(0.5)
30 .size(12)
31 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
32 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
33 .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
34 .x_title("body mass (g)")
35 .y_title("flipper length (mm)")
36 .legend_title("species")
37 .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
38 .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
39 .legend(&Legend::new().x(0.85).y(0.15))
40 .build()
41 .plot();
42}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}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}Sourcepub fn show_axis(self, bool: bool) -> Self
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?
More examples
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}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}Sourcepub fn axis_side(self, side: AxisSide) -> Self
pub fn axis_side(self, side: AxisSide) -> Self
Sets the side of the axis.
§Argument
side- AnAxisSideenum value representing the side of the axis.
Examples found in repository?
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}Sourcepub fn axis_position(self, position: f64) -> Self
pub fn axis_position(self, position: f64) -> Self
Sets the position of the axis.
§Argument
position- Af64value representing the position of the axis.
Examples found in repository?
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}Sourcepub fn axis_type(self, axis_type: AxisType) -> Self
pub fn axis_type(self, axis_type: AxisType) -> Self
Sets the type of the axis.
§Argument
axis_type- AnAxisTypeenum value representing the type of the axis.
Sourcepub fn value_color(self, color: Rgb) -> Self
pub fn value_color(self, color: Rgb) -> Self
Sets the color of the axis values.
§Argument
color- AnRgbstruct representing the color of the axis values.
Examples found in repository?
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}Sourcepub fn value_range(self, range: Vec<f64>) -> Self
pub fn value_range(self, range: Vec<f64>) -> Self
Sets the range of values displayed on the axis.
§Argument
range- A vector off64values representing the range of the axis.
Examples found in repository?
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| if a.len() == b.len() { a.cmp(b) } else { a.len().cmp(&b.len()) }) //sort by length unless equal length then lexical
29 .opacity(0.5)
30 .size(12)
31 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
32 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
33 .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
34 .x_title("body mass (g)")
35 .y_title("flipper length (mm)")
36 .legend_title("species")
37 .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
38 .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
39 .legend(&Legend::new().x(0.85).y(0.15))
40 .build()
41 .plot();
42}Sourcepub fn value_thousands(self, bool: bool) -> Self
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?
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
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}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| if a.len() == b.len() { a.cmp(b) } else { a.len().cmp(&b.len()) }) //sort by length unless equal length then lexical
29 .opacity(0.5)
30 .size(12)
31 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
32 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
33 .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
34 .x_title("body mass (g)")
35 .y_title("flipper length (mm)")
36 .legend_title("species")
37 .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
38 .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
39 .legend(&Legend::new().x(0.85).y(0.15))
40 .build()
41 .plot();
42}Sourcepub fn value_exponent(self, exponent: ValueExponent) -> Self
pub fn value_exponent(self, exponent: ValueExponent) -> Self
Sets the exponent format for values on the axis.
§Argument
exponent- AValueExponentenum value representing the exponent format.
Sourcepub fn tick_values(self, values: Vec<f64>) -> Self
pub fn tick_values(self, values: Vec<f64>) -> Self
Sets the tick values for the axis.
§Argument
values- A vector off64values representing the tick values.
Examples found in repository?
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}Sourcepub fn tick_labels(self, labels: Vec<impl Into<String>>) -> Self
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 intoString, representing the tick labels.
Examples found in repository?
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}Sourcepub fn tick_direction(self, direction: TickDirection) -> Self
pub fn tick_direction(self, direction: TickDirection) -> Self
Sets the direction of the axis ticks.
§Argument
direction- ATickDirectionenum value representing the direction of the ticks.
Examples found in repository?
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
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| if a.len() == b.len() { a.cmp(b) } else { a.len().cmp(&b.len()) }) //sort by length unless equal length then lexical
29 .opacity(0.5)
30 .size(12)
31 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
32 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
33 .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
34 .x_title("body mass (g)")
35 .y_title("flipper length (mm)")
36 .legend_title("species")
37 .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
38 .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
39 .legend(&Legend::new().x(0.85).y(0.15))
40 .build()
41 .plot();
42}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}Sourcepub fn tick_length(self, length: usize) -> Self
pub fn tick_length(self, length: usize) -> Self
Sets the length of the axis ticks.
§Argument
length- Ausizevalue representing the length of the ticks.
Sourcepub fn tick_width(self, width: usize) -> Self
pub fn tick_width(self, width: usize) -> Self
Sets the width of the axis ticks.
§Argument
width- Ausizevalue representing the width of the ticks.
Sourcepub fn tick_color(self, color: Rgb) -> Self
pub fn tick_color(self, color: Rgb) -> Self
Sets the color of the axis ticks.
§Argument
color- AnRgbstruct representing the color of the ticks.
Sourcepub fn tick_angle(self, angle: f64) -> Self
pub fn tick_angle(self, angle: f64) -> Self
Sets the angle of the axis ticks.
§Argument
angle- Af64value representing the angle of the ticks in degrees.
Sourcepub fn tick_font(self, font: impl Into<String>) -> Self
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 aString, representing the font name for the tick labels.
Sourcepub fn show_line(self, bool: bool) -> Self
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?
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
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| if a.len() == b.len() { a.cmp(b) } else { a.len().cmp(&b.len()) }) //sort by length unless equal length then lexical
29 .opacity(0.5)
30 .size(12)
31 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
32 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
33 .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
34 .x_title("body mass (g)")
35 .y_title("flipper length (mm)")
36 .legend_title("species")
37 .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
38 .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
39 .legend(&Legend::new().x(0.85).y(0.15))
40 .build()
41 .plot();
42}Sourcepub fn line_color(self, color: Rgb) -> Self
pub fn line_color(self, color: Rgb) -> Self
Sets the color of the axis line.
§Argument
color- AnRgbstruct representing the color of the axis line.
Sourcepub fn line_width(self, width: usize) -> Self
pub fn line_width(self, width: usize) -> Self
Sets the width of the axis line.
§Argument
width- Ausizevalue representing the width of the axis line.
Sourcepub fn show_grid(self, bool: bool) -> Self
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?
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
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}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}Sourcepub fn grid_color(self, color: Rgb) -> Self
pub fn grid_color(self, color: Rgb) -> Self
Sets the color of the grid lines on the axis.
§Argument
color- AnRgbstruct representing the color of the grid lines.
Sourcepub fn grid_width(self, width: usize) -> Self
pub fn grid_width(self, width: usize) -> Self
Sets the width of the grid lines on the axis.
§Argument
width- Ausizevalue representing the width of the grid lines.
Sourcepub fn show_zero_line(self, bool: bool) -> Self
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.
Sourcepub fn zero_line_color(self, color: Rgb) -> Self
pub fn zero_line_color(self, color: Rgb) -> Self
Sets the color of the zero line on the axis.
§Argument
color- AnRgbstruct representing the color of the zero line.
Examples found in repository?
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}Sourcepub fn zero_line_width(self, width: usize) -> Self
pub fn zero_line_width(self, width: usize) -> Self
Sets the width of the zero line on the axis.
§Argument
width- Ausizevalue representing the width of the zero line.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().