MCPcopy Create free account
hub / github.com/cpmech/plotpy / test_plot

Function test_plot

tests/test_plot.rs:10–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9#[test]
10fn test_plot() -> Result<(), StrError> {
11 // curve object and options
12 let mut curve = Curve::new();
13
14 // draw curve
15 let x = &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0];
16 let y = &[1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 3.5, 3.5, 3.5, 3.5];
17 curve.draw(x, y);
18
19 // configure plot
20 let mut plot = Plot::new();
21 plot.set_subplot(2, 2, 1)
22 .set_horizontal_gap(0.1)
23 .set_vertical_gap(0.2)
24 .set_gaps(0.3, 0.4)
25 .set_equal_axes(true)
26 .set_hide_axes(false)
27 .set_range(-1.0, 1.0, -1.0, 1.0)
28 .set_range_from_vec(&[0.0, 1.0, 0.0, 1.0])
29 .set_xmin(0.0)
30 .set_xmax(1.0)
31 .set_ymin(0.0)
32 .set_ymax(1.0)
33 .set_xrange(0.0, 1.0)
34 .set_yrange(0.0, 1.0)
35 .set_num_ticks_x(0)
36 .set_num_ticks_x(8)
37 .set_num_ticks_y(0)
38 .set_num_ticks_y(5)
39 .set_save_transparent(true)
40 .set_label_x("x-label")
41 .set_label_y("y-label")
42 .set_labels("x", "y")
43 .clear_current_axes();
44 plot.clear_current_figure();
45 plot.set_title("my plot'") // the extra "'" should be sanitized
46 .set_frame_borders(false)
47 .set_frame_borders(true)
48 .set_frame_borders(false)
49 .set_ticks_x(1.5, 0.5, "%.2f")
50 .set_ticks_y(0.5, 0.1, "%g");
51 plot.grid_and_labels("x", "y");
52
53 // add curve to plot
54 plot.add(&curve);
55
56 // save figure
57 let path = Path::new(OUT_DIR).join("integ_plot.svg");
58 plot.set_figure_size_points(250.0, 250.0 * 0.75);
59 plot.save(&path)?;
60
61 // check number of lines
62 let file = File::open(path).map_err(|_| "cannot open file")?;
63 let buffered = BufReader::new(file);
64 let lines_iter = buffered.lines();
65 assert!(lines_iter.count() > 900);
66 Ok(())
67}

Callers

nothing calls this directly

Calls 15

clear_current_axesMethod · 0.80
set_labelsMethod · 0.80
set_label_yMethod · 0.80
set_label_xMethod · 0.80
set_save_transparentMethod · 0.80
set_num_ticks_yMethod · 0.80
set_num_ticks_xMethod · 0.80
set_yrangeMethod · 0.80
set_xrangeMethod · 0.80
set_ymaxMethod · 0.80
set_yminMethod · 0.80
set_xmaxMethod · 0.80

Tested by

no test coverage detected