Text

Struct Text 

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

A structure representing text with customizable content, font, size, and color.

§Example

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

let dataset = df![
        "label" => &[""],
        "value" => &[0],
    ]
    .unwrap();

let axis = Axis::new()
    .tick_values(vec![]);

BarPlot::builder()
    .data(&dataset)
    .labels("label")
    .values("value")
    .plot_title(
        Text::from("Title")
            .x(0.1)
            .color(Rgb(178, 34, 34))
            .size(30)
            .font("Zapfino")
    )
    .x_title(
        Text::from("X")
            .color(Rgb(65, 105, 225))
            .size(20)
            .font("Marker Felt")
    )
    .y_title(
        Text::from("Y")
            .color(Rgb(255, 140, 0))
            .size(20)
            .font("Arial Black")
    )
    .x_axis(&axis)
    .y_axis(&axis)
    .build()
    .plot();

Example

Implementations§

Source§

impl Text

Source

pub fn from(content: impl Into<String>) -> Self

Creates a new Text instance from the given content.

§Argument
  • content - A value that can be converted into a String, representing the textual content.
Examples found in repository?
examples/array2dplot.rs (line 12)
3fn main() {
4    let data = vec![
5        vec![[255, 0, 0], [0, 255, 0], [0, 0, 255]],
6        vec![[0, 0, 255], [255, 0, 0], [0, 255, 0]],
7        vec![[0, 255, 0], [0, 0, 255], [255, 0, 0]],
8    ];
9
10    Array2dPlot::builder()
11        .data(&data)
12        .plot_title(Text::from("Array 2D Plot").font("Arial").size(18))
13        .build()
14        .plot();
15}
More examples
Hide additional examples
examples/piechart.rs (line 19)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([col("species")])
10        .collect()
11        .unwrap();
12
13    PieChart::builder()
14        .data(&dataset)
15        .labels("species")
16        .hole(0.4)
17        .pull(0.01)
18        .rotation(20.0)
19        .plot_title(Text::from("Pie Chart").font("Arial").size(18))
20        .build()
21        .plot();
22}
examples/scattermap.rs (line 21)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/cities.csv"))
7        .finish()
8        .unwrap()
9        .collect()
10        .unwrap();
11
12    ScatterMap::builder()
13        .data(&dataset)
14        .latitude("latitude")
15        .longitude("longitude")
16        .center([48.856613, 2.352222])
17        .zoom(4)
18        .group("city")
19        .opacity(0.5)
20        .size(12)
21        .plot_title(Text::from("Scatter Map").font("Arial").size(18))
22        .legend_title("cities")
23        .build()
24        .plot();
25}
examples/contourplot.rs (line 22)
5fn main() {
6    let dataset = df!(
7        "x" => &[0.0, 0.0, 0.0, 2.5, 2.5, 2.5, 5.0, 5.0, 5.0],
8        "y" => &[0.0, 7.5, 15.0, 0.0, 7.5, 15.0, 0.0, 7.5, 15.0],
9        "z" => &[0.0, 5.0, 10.0, 5.0, 2.5, 5.0, 10.0, 0.0, 0.0],
10    )
11    .unwrap();
12
13    ContourPlot::builder()
14        .data(&dataset)
15        .x("x")
16        .y("y")
17        .z("z")
18        .color_scale(Palette::Viridis)
19        .reverse_scale(true)
20        .coloring(Coloring::Fill)
21        .show_lines(false)
22        .plot_title(Text::from("Contour Plot").font("Arial").size(18))
23        .build()
24        .plot();
25}
examples/heatmap.rs (line 25)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/heatmap.csv"))
7        .finish()
8        .unwrap()
9        .collect()
10        .unwrap();
11
12    HeatMap::builder()
13        .data(&dataset)
14        .x("x")
15        .y("y")
16        .z("z")
17        .color_bar(
18            &ColorBar::new()
19                .length(290)
20                .value_exponent(ValueExponent::None)
21                .separate_thousands(true)
22                .tick_length(5)
23                .tick_step(2500.0),
24        )
25        .plot_title(Text::from("Heat Map").font("Arial").size(18))
26        .color_scale(Palette::Viridis)
27        .build()
28        .plot();
29}
examples/scatterpolar.rs (line 37)
18fn basic_scatter_polar() {
19    // Create sample data - wind direction and speed
20    let directions = vec![0., 45., 90., 135., 180., 225., 270., 315., 360.];
21    let speeds = vec![5.0, 7.5, 10.0, 8.5, 6.0, 4.5, 3.0, 2.5, 5.0];
22
23    let dataset = DataFrame::new(vec![
24        Column::new("direction".into(), directions),
25        Column::new("speed".into(), speeds),
26    ])
27    .unwrap();
28
29    ScatterPolar::builder()
30        .data(&dataset)
31        .theta("direction")
32        .r("speed")
33        .mode(Mode::Markers)
34        .color(Rgb(65, 105, 225))
35        .shape(Shape::Circle)
36        .size(10)
37        .plot_title(Text::from("Wind Speed by Direction").font("Arial").size(20))
38        .build()
39        .plot();
40}
41
42fn styled_scatter_polar() {
43    // Create sample data - radar chart style
44    let categories = vec![0., 72., 144., 216., 288., 360.];
45    let performance = vec![8.0, 6.5, 7.0, 9.0, 5.5, 8.0];
46
47    let dataset = DataFrame::new(vec![
48        Column::new("category".into(), categories),
49        Column::new("performance".into(), performance),
50    ])
51    .unwrap();
52
53    ScatterPolar::builder()
54        .data(&dataset)
55        .theta("category")
56        .r("performance")
57        .mode(Mode::LinesMarkers)
58        .color(Rgb(255, 0, 0))
59        .shape(Shape::Diamond)
60        .line(Line::Solid)
61        .width(3.0)
62        .size(12)
63        .opacity(0.8)
64        .plot_title(
65            Text::from("Performance Radar Chart")
66                .font("Arial")
67                .size(22)
68                .x(0.5),
69        )
70        .build()
71        .plot();
72}
73
74fn grouped_scatter_polar() {
75    // Create sample data - comparing two products across multiple metrics
76    let angles = vec![
77        0., 60., 120., 180., 240., 300., 360., // Product A
78        0., 60., 120., 180., 240., 300., 360., // Product B
79    ];
80    let values = vec![
81        7.0, 8.5, 6.0, 5.5, 9.0, 8.0, 7.0, // Product A values
82        6.0, 7.0, 8.0, 9.0, 6.5, 7.5, 6.0, // Product B values
83    ];
84    let products = vec![
85        "Product A",
86        "Product A",
87        "Product A",
88        "Product A",
89        "Product A",
90        "Product A",
91        "Product A",
92        "Product B",
93        "Product B",
94        "Product B",
95        "Product B",
96        "Product B",
97        "Product B",
98        "Product B",
99    ];
100
101    let dataset = DataFrame::new(vec![
102        Column::new("angle".into(), angles),
103        Column::new("score".into(), values),
104        Column::new("product".into(), products),
105    ])
106    .unwrap();
107
108    ScatterPolar::builder()
109        .data(&dataset)
110        .theta("angle")
111        .r("score")
112        .group("product")
113        .mode(Mode::LinesMarkers)
114        .colors(vec![
115            Rgb(255, 99, 71),  // Tomato red
116            Rgb(60, 179, 113), // Medium sea green
117        ])
118        .shapes(vec![Shape::Circle, Shape::Square])
119        .lines(vec![Line::Solid, Line::Dash])
120        .width(2.5)
121        .size(8)
122        .plot_title(Text::from("Product Comparison").font("Arial").size(24))
123        .legend_title(Text::from("Products").font("Arial").size(14))
124        .legend(&Legend::new().x(0.85).y(0.95))
125        .build()
126        .plot();
127}
128
129fn filled_scatter_polar() {
130    // Create sample data - filled area chart
131    let angles: Vec<f64> = (0..=360).step_by(10).map(|x| x as f64).collect();
132    let radii: Vec<f64> = angles
133        .iter()
134        .map(|&angle| 5.0 + 3.0 * (angle * std::f64::consts::PI / 180.0).sin())
135        .collect();
136
137    let dataset = DataFrame::new(vec![
138        Column::new("angle".into(), angles),
139        Column::new("radius".into(), radii),
140    ])
141    .unwrap();
142
143    ScatterPolar::builder()
144        .data(&dataset)
145        .theta("angle")
146        .r("radius")
147        .mode(Mode::Lines)
148        .fill(Fill::ToSelf)
149        .color(Rgb(135, 206, 250))
150        .line(Line::Solid)
151        .width(2.0)
152        .opacity(0.6)
153        .plot_title(Text::from("Filled Polar Area Chart").font("Arial").size(20))
154        .build()
155        .plot();
156}
Source

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

Sets the font of the text.

§Argument
  • font - A value that can be converted into a String, representing the font name.
Examples found in repository?
examples/array2dplot.rs (line 12)
3fn main() {
4    let data = vec![
5        vec![[255, 0, 0], [0, 255, 0], [0, 0, 255]],
6        vec![[0, 0, 255], [255, 0, 0], [0, 255, 0]],
7        vec![[0, 255, 0], [0, 0, 255], [255, 0, 0]],
8    ];
9
10    Array2dPlot::builder()
11        .data(&data)
12        .plot_title(Text::from("Array 2D Plot").font("Arial").size(18))
13        .build()
14        .plot();
15}
More examples
Hide additional examples
examples/piechart.rs (line 19)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([col("species")])
10        .collect()
11        .unwrap();
12
13    PieChart::builder()
14        .data(&dataset)
15        .labels("species")
16        .hole(0.4)
17        .pull(0.01)
18        .rotation(20.0)
19        .plot_title(Text::from("Pie Chart").font("Arial").size(18))
20        .build()
21        .plot();
22}
examples/scattermap.rs (line 21)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/cities.csv"))
7        .finish()
8        .unwrap()
9        .collect()
10        .unwrap();
11
12    ScatterMap::builder()
13        .data(&dataset)
14        .latitude("latitude")
15        .longitude("longitude")
16        .center([48.856613, 2.352222])
17        .zoom(4)
18        .group("city")
19        .opacity(0.5)
20        .size(12)
21        .plot_title(Text::from("Scatter Map").font("Arial").size(18))
22        .legend_title("cities")
23        .build()
24        .plot();
25}
examples/contourplot.rs (line 22)
5fn main() {
6    let dataset = df!(
7        "x" => &[0.0, 0.0, 0.0, 2.5, 2.5, 2.5, 5.0, 5.0, 5.0],
8        "y" => &[0.0, 7.5, 15.0, 0.0, 7.5, 15.0, 0.0, 7.5, 15.0],
9        "z" => &[0.0, 5.0, 10.0, 5.0, 2.5, 5.0, 10.0, 0.0, 0.0],
10    )
11    .unwrap();
12
13    ContourPlot::builder()
14        .data(&dataset)
15        .x("x")
16        .y("y")
17        .z("z")
18        .color_scale(Palette::Viridis)
19        .reverse_scale(true)
20        .coloring(Coloring::Fill)
21        .show_lines(false)
22        .plot_title(Text::from("Contour Plot").font("Arial").size(18))
23        .build()
24        .plot();
25}
examples/heatmap.rs (line 25)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/heatmap.csv"))
7        .finish()
8        .unwrap()
9        .collect()
10        .unwrap();
11
12    HeatMap::builder()
13        .data(&dataset)
14        .x("x")
15        .y("y")
16        .z("z")
17        .color_bar(
18            &ColorBar::new()
19                .length(290)
20                .value_exponent(ValueExponent::None)
21                .separate_thousands(true)
22                .tick_length(5)
23                .tick_step(2500.0),
24        )
25        .plot_title(Text::from("Heat Map").font("Arial").size(18))
26        .color_scale(Palette::Viridis)
27        .build()
28        .plot();
29}
examples/scatterpolar.rs (line 37)
18fn basic_scatter_polar() {
19    // Create sample data - wind direction and speed
20    let directions = vec![0., 45., 90., 135., 180., 225., 270., 315., 360.];
21    let speeds = vec![5.0, 7.5, 10.0, 8.5, 6.0, 4.5, 3.0, 2.5, 5.0];
22
23    let dataset = DataFrame::new(vec![
24        Column::new("direction".into(), directions),
25        Column::new("speed".into(), speeds),
26    ])
27    .unwrap();
28
29    ScatterPolar::builder()
30        .data(&dataset)
31        .theta("direction")
32        .r("speed")
33        .mode(Mode::Markers)
34        .color(Rgb(65, 105, 225))
35        .shape(Shape::Circle)
36        .size(10)
37        .plot_title(Text::from("Wind Speed by Direction").font("Arial").size(20))
38        .build()
39        .plot();
40}
41
42fn styled_scatter_polar() {
43    // Create sample data - radar chart style
44    let categories = vec![0., 72., 144., 216., 288., 360.];
45    let performance = vec![8.0, 6.5, 7.0, 9.0, 5.5, 8.0];
46
47    let dataset = DataFrame::new(vec![
48        Column::new("category".into(), categories),
49        Column::new("performance".into(), performance),
50    ])
51    .unwrap();
52
53    ScatterPolar::builder()
54        .data(&dataset)
55        .theta("category")
56        .r("performance")
57        .mode(Mode::LinesMarkers)
58        .color(Rgb(255, 0, 0))
59        .shape(Shape::Diamond)
60        .line(Line::Solid)
61        .width(3.0)
62        .size(12)
63        .opacity(0.8)
64        .plot_title(
65            Text::from("Performance Radar Chart")
66                .font("Arial")
67                .size(22)
68                .x(0.5),
69        )
70        .build()
71        .plot();
72}
73
74fn grouped_scatter_polar() {
75    // Create sample data - comparing two products across multiple metrics
76    let angles = vec![
77        0., 60., 120., 180., 240., 300., 360., // Product A
78        0., 60., 120., 180., 240., 300., 360., // Product B
79    ];
80    let values = vec![
81        7.0, 8.5, 6.0, 5.5, 9.0, 8.0, 7.0, // Product A values
82        6.0, 7.0, 8.0, 9.0, 6.5, 7.5, 6.0, // Product B values
83    ];
84    let products = vec![
85        "Product A",
86        "Product A",
87        "Product A",
88        "Product A",
89        "Product A",
90        "Product A",
91        "Product A",
92        "Product B",
93        "Product B",
94        "Product B",
95        "Product B",
96        "Product B",
97        "Product B",
98        "Product B",
99    ];
100
101    let dataset = DataFrame::new(vec![
102        Column::new("angle".into(), angles),
103        Column::new("score".into(), values),
104        Column::new("product".into(), products),
105    ])
106    .unwrap();
107
108    ScatterPolar::builder()
109        .data(&dataset)
110        .theta("angle")
111        .r("score")
112        .group("product")
113        .mode(Mode::LinesMarkers)
114        .colors(vec![
115            Rgb(255, 99, 71),  // Tomato red
116            Rgb(60, 179, 113), // Medium sea green
117        ])
118        .shapes(vec![Shape::Circle, Shape::Square])
119        .lines(vec![Line::Solid, Line::Dash])
120        .width(2.5)
121        .size(8)
122        .plot_title(Text::from("Product Comparison").font("Arial").size(24))
123        .legend_title(Text::from("Products").font("Arial").size(14))
124        .legend(&Legend::new().x(0.85).y(0.95))
125        .build()
126        .plot();
127}
128
129fn filled_scatter_polar() {
130    // Create sample data - filled area chart
131    let angles: Vec<f64> = (0..=360).step_by(10).map(|x| x as f64).collect();
132    let radii: Vec<f64> = angles
133        .iter()
134        .map(|&angle| 5.0 + 3.0 * (angle * std::f64::consts::PI / 180.0).sin())
135        .collect();
136
137    let dataset = DataFrame::new(vec![
138        Column::new("angle".into(), angles),
139        Column::new("radius".into(), radii),
140    ])
141    .unwrap();
142
143    ScatterPolar::builder()
144        .data(&dataset)
145        .theta("angle")
146        .r("radius")
147        .mode(Mode::Lines)
148        .fill(Fill::ToSelf)
149        .color(Rgb(135, 206, 250))
150        .line(Line::Solid)
151        .width(2.0)
152        .opacity(0.6)
153        .plot_title(Text::from("Filled Polar Area Chart").font("Arial").size(20))
154        .build()
155        .plot();
156}
Source

pub fn size(self, size: usize) -> Self

Sets the size of the text.

§Argument
  • size - A usize value specifying the font size.
Examples found in repository?
examples/array2dplot.rs (line 12)
3fn main() {
4    let data = vec![
5        vec![[255, 0, 0], [0, 255, 0], [0, 0, 255]],
6        vec![[0, 0, 255], [255, 0, 0], [0, 255, 0]],
7        vec![[0, 255, 0], [0, 0, 255], [255, 0, 0]],
8    ];
9
10    Array2dPlot::builder()
11        .data(&data)
12        .plot_title(Text::from("Array 2D Plot").font("Arial").size(18))
13        .build()
14        .plot();
15}
More examples
Hide additional examples
examples/piechart.rs (line 19)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7        .finish()
8        .unwrap()
9        .select([col("species")])
10        .collect()
11        .unwrap();
12
13    PieChart::builder()
14        .data(&dataset)
15        .labels("species")
16        .hole(0.4)
17        .pull(0.01)
18        .rotation(20.0)
19        .plot_title(Text::from("Pie Chart").font("Arial").size(18))
20        .build()
21        .plot();
22}
examples/scattermap.rs (line 21)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/cities.csv"))
7        .finish()
8        .unwrap()
9        .collect()
10        .unwrap();
11
12    ScatterMap::builder()
13        .data(&dataset)
14        .latitude("latitude")
15        .longitude("longitude")
16        .center([48.856613, 2.352222])
17        .zoom(4)
18        .group("city")
19        .opacity(0.5)
20        .size(12)
21        .plot_title(Text::from("Scatter Map").font("Arial").size(18))
22        .legend_title("cities")
23        .build()
24        .plot();
25}
examples/contourplot.rs (line 22)
5fn main() {
6    let dataset = df!(
7        "x" => &[0.0, 0.0, 0.0, 2.5, 2.5, 2.5, 5.0, 5.0, 5.0],
8        "y" => &[0.0, 7.5, 15.0, 0.0, 7.5, 15.0, 0.0, 7.5, 15.0],
9        "z" => &[0.0, 5.0, 10.0, 5.0, 2.5, 5.0, 10.0, 0.0, 0.0],
10    )
11    .unwrap();
12
13    ContourPlot::builder()
14        .data(&dataset)
15        .x("x")
16        .y("y")
17        .z("z")
18        .color_scale(Palette::Viridis)
19        .reverse_scale(true)
20        .coloring(Coloring::Fill)
21        .show_lines(false)
22        .plot_title(Text::from("Contour Plot").font("Arial").size(18))
23        .build()
24        .plot();
25}
examples/heatmap.rs (line 25)
5fn main() {
6    let dataset = LazyCsvReader::new(PlPath::new("data/heatmap.csv"))
7        .finish()
8        .unwrap()
9        .collect()
10        .unwrap();
11
12    HeatMap::builder()
13        .data(&dataset)
14        .x("x")
15        .y("y")
16        .z("z")
17        .color_bar(
18            &ColorBar::new()
19                .length(290)
20                .value_exponent(ValueExponent::None)
21                .separate_thousands(true)
22                .tick_length(5)
23                .tick_step(2500.0),
24        )
25        .plot_title(Text::from("Heat Map").font("Arial").size(18))
26        .color_scale(Palette::Viridis)
27        .build()
28        .plot();
29}
examples/scatterpolar.rs (line 37)
18fn basic_scatter_polar() {
19    // Create sample data - wind direction and speed
20    let directions = vec![0., 45., 90., 135., 180., 225., 270., 315., 360.];
21    let speeds = vec![5.0, 7.5, 10.0, 8.5, 6.0, 4.5, 3.0, 2.5, 5.0];
22
23    let dataset = DataFrame::new(vec![
24        Column::new("direction".into(), directions),
25        Column::new("speed".into(), speeds),
26    ])
27    .unwrap();
28
29    ScatterPolar::builder()
30        .data(&dataset)
31        .theta("direction")
32        .r("speed")
33        .mode(Mode::Markers)
34        .color(Rgb(65, 105, 225))
35        .shape(Shape::Circle)
36        .size(10)
37        .plot_title(Text::from("Wind Speed by Direction").font("Arial").size(20))
38        .build()
39        .plot();
40}
41
42fn styled_scatter_polar() {
43    // Create sample data - radar chart style
44    let categories = vec![0., 72., 144., 216., 288., 360.];
45    let performance = vec![8.0, 6.5, 7.0, 9.0, 5.5, 8.0];
46
47    let dataset = DataFrame::new(vec![
48        Column::new("category".into(), categories),
49        Column::new("performance".into(), performance),
50    ])
51    .unwrap();
52
53    ScatterPolar::builder()
54        .data(&dataset)
55        .theta("category")
56        .r("performance")
57        .mode(Mode::LinesMarkers)
58        .color(Rgb(255, 0, 0))
59        .shape(Shape::Diamond)
60        .line(Line::Solid)
61        .width(3.0)
62        .size(12)
63        .opacity(0.8)
64        .plot_title(
65            Text::from("Performance Radar Chart")
66                .font("Arial")
67                .size(22)
68                .x(0.5),
69        )
70        .build()
71        .plot();
72}
73
74fn grouped_scatter_polar() {
75    // Create sample data - comparing two products across multiple metrics
76    let angles = vec![
77        0., 60., 120., 180., 240., 300., 360., // Product A
78        0., 60., 120., 180., 240., 300., 360., // Product B
79    ];
80    let values = vec![
81        7.0, 8.5, 6.0, 5.5, 9.0, 8.0, 7.0, // Product A values
82        6.0, 7.0, 8.0, 9.0, 6.5, 7.5, 6.0, // Product B values
83    ];
84    let products = vec![
85        "Product A",
86        "Product A",
87        "Product A",
88        "Product A",
89        "Product A",
90        "Product A",
91        "Product A",
92        "Product B",
93        "Product B",
94        "Product B",
95        "Product B",
96        "Product B",
97        "Product B",
98        "Product B",
99    ];
100
101    let dataset = DataFrame::new(vec![
102        Column::new("angle".into(), angles),
103        Column::new("score".into(), values),
104        Column::new("product".into(), products),
105    ])
106    .unwrap();
107
108    ScatterPolar::builder()
109        .data(&dataset)
110        .theta("angle")
111        .r("score")
112        .group("product")
113        .mode(Mode::LinesMarkers)
114        .colors(vec![
115            Rgb(255, 99, 71),  // Tomato red
116            Rgb(60, 179, 113), // Medium sea green
117        ])
118        .shapes(vec![Shape::Circle, Shape::Square])
119        .lines(vec![Line::Solid, Line::Dash])
120        .width(2.5)
121        .size(8)
122        .plot_title(Text::from("Product Comparison").font("Arial").size(24))
123        .legend_title(Text::from("Products").font("Arial").size(14))
124        .legend(&Legend::new().x(0.85).y(0.95))
125        .build()
126        .plot();
127}
128
129fn filled_scatter_polar() {
130    // Create sample data - filled area chart
131    let angles: Vec<f64> = (0..=360).step_by(10).map(|x| x as f64).collect();
132    let radii: Vec<f64> = angles
133        .iter()
134        .map(|&angle| 5.0 + 3.0 * (angle * std::f64::consts::PI / 180.0).sin())
135        .collect();
136
137    let dataset = DataFrame::new(vec![
138        Column::new("angle".into(), angles),
139        Column::new("radius".into(), radii),
140    ])
141    .unwrap();
142
143    ScatterPolar::builder()
144        .data(&dataset)
145        .theta("angle")
146        .r("radius")
147        .mode(Mode::Lines)
148        .fill(Fill::ToSelf)
149        .color(Rgb(135, 206, 250))
150        .line(Line::Solid)
151        .width(2.0)
152        .opacity(0.6)
153        .plot_title(Text::from("Filled Polar Area Chart").font("Arial").size(20))
154        .build()
155        .plot();
156}
Source

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

Sets the color of the text.

§Argument
  • color - An Rgb value specifying the color of the text.
Examples found in repository?
examples/table.rs (line 40)
5fn main() {
6    let dataset = df![
7        "name" => &["Alice Johnson", "Bob Smith", "Charlie Davis", "Diana Martinez", "Eva Wilson"],
8        "department" => &["Engineering", "Marketing", "Engineering", "Sales", "Marketing"],
9        "salary" => &[95000, 78000, 102000, 85000, 82000],
10        "years" => &[5, 3, 7, 4, 2]
11    ]
12    .unwrap();
13
14    let header = Header::new()
15        .values(vec![
16            "Employee Name",
17            "Department",
18            "Annual Salary ($)",
19            "Years of Service",
20        ])
21        .align("center")
22        .font("Arial Bold")
23        .fill(Rgb(70, 130, 180));
24
25    let cell = Cell::new()
26        .align("center")
27        .height(25.0)
28        .font("Arial")
29        .fill(Rgb(240, 248, 255));
30
31    Table::builder()
32        .data(&dataset)
33        .columns(vec!["name", "department", "salary", "years"])
34        .header(&header)
35        .cell(&cell)
36        .plot_title(
37            Text::from("Employee Data")
38                .font("Arial")
39                .size(20)
40                .color(Rgb(25, 25, 112)),
41        )
42        .build()
43        .plot();
44}
More examples
Hide additional examples
examples/timeseriesplot.rs (line 31)
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 x(self, x: f64) -> Self

Sets the x-coordinate position of the text.

§Argument
  • x - A f64 value specifying the horizontal position.
Examples found in repository?
examples/scatterpolar.rs (line 68)
42fn styled_scatter_polar() {
43    // Create sample data - radar chart style
44    let categories = vec![0., 72., 144., 216., 288., 360.];
45    let performance = vec![8.0, 6.5, 7.0, 9.0, 5.5, 8.0];
46
47    let dataset = DataFrame::new(vec![
48        Column::new("category".into(), categories),
49        Column::new("performance".into(), performance),
50    ])
51    .unwrap();
52
53    ScatterPolar::builder()
54        .data(&dataset)
55        .theta("category")
56        .r("performance")
57        .mode(Mode::LinesMarkers)
58        .color(Rgb(255, 0, 0))
59        .shape(Shape::Diamond)
60        .line(Line::Solid)
61        .width(3.0)
62        .size(12)
63        .opacity(0.8)
64        .plot_title(
65            Text::from("Performance Radar Chart")
66                .font("Arial")
67                .size(22)
68                .x(0.5),
69        )
70        .build()
71        .plot();
72}
More examples
Hide additional examples
examples/scatterplot.rs (line 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    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/scattergeo.rs (line 56)
4fn main() {
5    // Example 1: Basic ScatterGeo with markers only
6    let cities = df![
7        "city" => ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"],
8        "lat" => [40.7128, 34.0522, 41.8781, 29.7604, 33.4484],
9        "lon" => [-74.0060, -118.2437, -87.6298, -95.3698, -112.0740],
10    ]
11    .unwrap();
12
13    ScatterGeo::builder()
14        .data(&cities)
15        .lat("lat")
16        .lon("lon")
17        .text("city")
18        .plot_title(Text::from("US Major Cities").font("Arial").size(20))
19        .build()
20        .plot();
21
22    // Example 2: ScatterGeo with grouping by region
23    let cities_with_regions = df![
24        "city" => ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose"],
25        "lat" => [40.7128, 34.0522, 41.8781, 29.7604, 33.4484, 39.9526, 29.4241, 32.7157, 32.7767, 37.3382],
26        "lon" => [-74.0060, -118.2437, -87.6298, -95.3698, -112.0740, -75.1652, -98.4936, -117.1611, -96.7970, -121.8863],
27        "population" => [8336817, 3979576, 2693976, 2320268, 1680992, 1584064, 1547253, 1423851, 1343573, 1021795],
28        "region" => ["Northeast", "West", "Midwest", "South", "West", "Northeast", "South", "West", "South", "West"]
29    ]
30    .unwrap();
31
32    ScatterGeo::builder()
33        .data(&cities_with_regions)
34        .lat("lat")
35        .lon("lon")
36        .mode(Mode::Markers)
37        .text("city")
38        .group("region")
39        .size(20)
40        .colors(vec![
41            Rgb(255, 0, 0),
42            Rgb(0, 255, 0),
43            Rgb(0, 0, 255),
44            Rgb(255, 165, 0),
45        ])
46        .shapes(vec![
47            Shape::Circle,
48            Shape::Square,
49            Shape::Diamond,
50            Shape::Cross,
51        ])
52        .plot_title(
53            Text::from("US Cities by Region")
54                .font("Arial")
55                .size(24)
56                .x(0.5),
57        )
58        .legend_title(Text::from("Region").size(14))
59        .build()
60        .plot();
61
62    // Example 3: ScatterGeo with lines connecting cities (flight paths)
63    let flight_path = df![
64        "city" => ["New York", "Chicago", "Denver", "Los Angeles"],
65        "lat" => [40.7128, 41.8781, 39.7392, 34.0522],
66        "lon" => [-74.0060, -87.6298, -104.9903, -118.2437],
67    ]
68    .unwrap();
69
70    ScatterGeo::builder()
71        .data(&flight_path)
72        .lat("lat")
73        .lon("lon")
74        .mode(Mode::LinesMarkers)
75        .text("city")
76        .size(15)
77        .color(Rgb(0, 123, 255))
78        .line_width(2.0)
79        .line_color(Rgb(255, 123, 0))
80        .opacity(0.8)
81        .plot_title(Text::from("Flight Path: NY to LA").font("Arial").size(20))
82        .build()
83        .plot();
84
85    // Example 4: World cities with custom styling
86    let world_cities = df![
87        "city" => ["London", "Paris", "Tokyo", "Sydney", "Cairo", "Mumbai", "Beijing", "Rio de Janeiro", "Toronto"],
88        "lat" => [51.5074, 48.8566, 35.6762, -33.8688, 30.0444, 19.0760, 39.9042, -22.9068, 43.6532],
89        "lon" => [-0.1278, 2.3522, 139.6503, 151.2093, 31.2357, 72.8777, 116.4074, -43.1729, -79.3832],
90        "continent" => ["Europe", "Europe", "Asia", "Oceania", "Africa", "Asia", "Asia", "South America", "North America"],
91        "population_millions" => [9.0, 2.2, 13.9, 5.3, 9.5, 12.4, 21.5, 6.7, 2.9]
92    ]
93    .unwrap();
94
95    ScatterGeo::builder()
96        .data(&world_cities)
97        .lat("lat")
98        .lon("lon")
99        .mode(Mode::Markers)
100        .text("city")
101        .group("continent")
102        .size(25)
103        .opacity(0.7)
104        .colors(vec![
105            Rgb(255, 0, 0),
106            Rgb(0, 255, 0),
107            Rgb(0, 0, 255),
108            Rgb(255, 255, 0),
109            Rgb(255, 0, 255),
110            Rgb(0, 255, 255),
111        ])
112        .plot_title(
113            Text::from("Major World Cities by Continent")
114                .font("Arial")
115                .size(24),
116        )
117        .legend_title(Text::from("Continent").size(16))
118        .build()
119        .plot();
120}
Source

pub fn y(self, y: f64) -> Self

Sets the y-coordinate position of the text.

§Argument
  • y - A f64 value specifying the vertical position.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

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 Text

Source§

fn default() -> Self

Provides default values for the Text struct.

  • content: An empty string.
  • font: An empty string.
  • size: 0.
  • color: Default Rgb value.
  • x: 0.5.
  • y: 0.9.
Source§

impl From<&String> for Text

Source§

fn from(content: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Text

Source§

fn from(content: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Text

Source§

fn from(content: String) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnwindSafe for Text

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