-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3d_plot.rs
More file actions
71 lines (57 loc) · 1.84 KB
/
3d_plot.rs
File metadata and controls
71 lines (57 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! 3d_plot example from plotters
mod test_utils;
use plotters::prelude::*;
use plotters_wxdragon::WxBackend;
use wxdragon::DeviceContext;
use test_utils::run_plotters_image_test;
#[test]
fn test_3d_plot() -> anyhow::Result<()> {
run_plotters_image_test(1024, 768, "tests/3d_plot", draw_3d_plot)
}
fn draw_3d_plot<C: DeviceContext>(backend: WxBackend<C>) -> anyhow::Result<()> {
let root_area = backend.into_drawing_area();
root_area.fill(&WHITE)?;
let x_axis = (-3.0..3.0).step(0.1);
let z_axis = (-3.0..3.0).step(0.1);
let mut chart = ChartBuilder::on(&root_area)
.caption("3D Plot Test", ("sans", 20))
.build_cartesian_3d(x_axis.clone(), -3.0..3.0, z_axis.clone())?;
chart.with_projection(|mut pb| {
pb.yaw = 0.5;
pb.scale = 0.9;
pb.into_matrix()
});
chart
.configure_axes()
.light_grid_style(BLACK.mix(0.15))
.max_light_lines(3)
.draw()?;
chart
.draw_series(
SurfaceSeries::xoz(
(-30..30).map(|f| f as f64 / 10.0),
(-30..30).map(|f| f as f64 / 10.0),
|x, z| (x * x + z * z).cos(),
)
.style(BLUE.mix(0.2).filled()),
)?
.label("Surface")
.legend(|(x, y)| {
Rectangle::new(
[(x + 5, y - 5), (x + 15, y + 5)],
BLUE.mix(0.5).filled(),
)
});
chart
.draw_series(LineSeries::new(
(-100..100)
.map(|y| y as f64 / 40.0)
.map(|y| ((y * 10.0).sin(), y, (y * 10.0).cos())),
&BLACK,
))?
.label("Line")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLACK));
chart.configure_series_labels().border_style(BLACK).draw()?;
root_area.present().expect("present");
Ok(())
}