MCPcopy Create free account
hub / github.com/douchuan/algorithm / main

Function main

examples/quadratic.rs:2–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1use plotters::prelude::*;
2fn main() -> Result<(), Box<dyn std::error::Error>> {
3 let root = BitMapBackend::new("plotters-doc-data/0.png", (640, 480)).into_drawing_area();
4 root.fill(&WHITE)?;
5 let mut chart = ChartBuilder::on(&root)
6 .caption("y=x^2", ("sans-serif", 50).into_font())
7 .margin(5)
8 .x_label_area_size(30)
9 .y_label_area_size(30)
10 .build_cartesian_2d(-1f32..1f32, -0.1f32..1f32)?;
11
12 chart.configure_mesh().draw()?;
13
14 chart
15 .draw_series(LineSeries::new(
16 (-50..=50).map(|x| x as f32 / 50.0).map(|x| (x, x * x)),
17 &RED,
18 ))?
19 .label("y = x^2")
20 .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));
21
22 chart
23 .configure_series_labels()
24 .background_style(&WHITE.mix(0.8))
25 .border_style(&BLACK)
26 .draw()?;
27
28 Ok(())
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected