MCPcopy Create free account
hub / github.com/alceal/plotlars / main

Function main

crates/plotlars/examples/plotly_lineplot.rs:4–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2use plotlars::{Axis, Line, LinePlot, Plot, Rgb, Text, TickDirection};
3
4fn main() {
5 let x_values: Vec<f64> = (0..1000)
6 .map(|i| {
7 let step = (2.0 * std::f64::consts::PI - 0.0) / 999.0;
8 0.0 + step * i as f64
9 })
10 .collect();
11 let sine_values = x_values
12 .iter()
13 .map(|arg0: &f64| f64::sin(*arg0))
14 .collect::<Vec<_>>();
15 let cosine_values = x_values
16 .iter()
17 .map(|arg0: &f64| f64::cos(*arg0))
18 .collect::<Vec<_>>();
19
20 let dataset = df![
21 "x" => &x_values,
22 "sine" => &sine_values,
23 "cosine" => &cosine_values,
24 ]
25 .unwrap();
26
27 LinePlot::builder()
28 .data(&dataset)
29 .x("x")
30 .y("sine")
31 .additional_lines(vec!["cosine"])
32 .colors(vec![Rgb(255, 0, 0), Rgb(0, 255, 0)])
33 .lines(vec![Line::Solid, Line::Dot])
34 .width(3.0)
35 .plot_title(Text::from("Line Plot").font("Arial").size(18))
36 .x_axis(
37 &Axis::new()
38 .tick_direction(TickDirection::OutSide)
39 .axis_position(0.5)
40 .tick_values(vec![
41 0.5 * std::f64::consts::PI,
42 std::f64::consts::PI,
43 1.5 * std::f64::consts::PI,
44 2.0 * std::f64::consts::PI,
45 ])
46 .tick_labels(vec!["π/2", "π", "3π/2", "2π"]),
47 )
48 .y_axis(
49 &Axis::new()
50 .tick_direction(TickDirection::OutSide)
51 .tick_values(vec![-1.0, 0.0, 1.0])
52 .tick_labels(vec!["-1", "0", "1"]),
53 )
54 .build()
55 .plot();
56}

Callers

nothing calls this directly

Calls 10

sizeMethod · 0.80
axis_positionMethod · 0.80
plotMethod · 0.45
widthMethod · 0.45
yMethod · 0.45
xMethod · 0.45
fontMethod · 0.45
tick_labelsMethod · 0.45
tick_valuesMethod · 0.45
tick_directionMethod · 0.45

Tested by

no test coverage detected