MCPcopy Create free account
hub / github.com/JakkuSakura/plotters-gpui / plot

Method plot

examples/3d-plot.rs:40–98  ·  view source on GitHub ↗
(
        &mut self,
        root: &DrawingArea<GpuiBackend, Shift>,
    )

Source from the content-addressed store, hash-verified

38struct MyChart;
39impl PlottersChart for MyChart {
40 fn plot(
41 &mut self,
42 root: &DrawingArea<GpuiBackend, Shift>,
43 ) -> Result<(), plotters_gpui::DrawingErrorKind> {
44 let x_axis = (-3.0..3.0).step(0.1);
45 let z_axis = (-3.0..3.0).step(0.1);
46
47 let mut chart = ChartBuilder::on(root)
48 .caption("3D Plot Test", ("sans", 20))
49 .build_cartesian_3d(x_axis.clone(), -3.0..3.0, z_axis.clone())
50 .unwrap();
51
52 chart.with_projection(|mut pb| {
53 pb.yaw = 0.5;
54 pb.scale = 0.9;
55 pb.into_matrix()
56 });
57
58 chart
59 .configure_axes()
60 .light_grid_style(BLACK.mix(0.15))
61 .max_light_lines(3)
62 .draw()
63 .unwrap();
64
65 chart
66 .draw_series(
67 SurfaceSeries::xoz(
68 (-30..30).map(|f| f as f64 / 10.0),
69 (-30..30).map(|f| f as f64 / 10.0),
70 |x, z| (x * x + z * z).cos(),
71 )
72 .style(BLUE.mix(0.2).filled()),
73 )
74 .unwrap()
75 .label("Surface")
76 .legend(|(x, y)| {
77 Rectangle::new([(x + 5, y - 5), (x + 15, y + 5)], BLUE.mix(0.5).filled())
78 });
79
80 chart
81 .draw_series(LineSeries::new(
82 (-100..100)
83 .map(|y| y as f64 / 40.0)
84 .map(|y| ((y * 10.0).sin(), y, (y * 10.0).cos())),
85 &BLACK,
86 ))
87 .unwrap()
88 .label("Line")
89 .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLACK));
90
91 chart
92 .configure_series_labels()
93 .border_style(BLACK)
94 .draw()
95 .unwrap();
96
97 Ok(())

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected