1use ndarray::Array;
2use polars::prelude::*;
3
4use plotlars::{Axis, Line, LinePlot, Plot, Rgb, Text, TickDirection};
5
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}