1
use plotlib::page::Page;
2
use plotlib::repr::Plot;
3
use plotlib::style::{PointMarker, PointStyle};
4
use plotlib::view::ContinuousView;
5

6
#[test]
7 1
fn test_data_with_one_length() {
8
    // Scatter plots expect a list of pairs
9 1
    let data1 = vec![(-3.0, 2.3)];
10

11
    // We create our scatter plot from the data
12 1
    let s1 = Plot::new(data1).point_style(
13 1
        PointStyle::new()
14
            .marker(PointMarker::Square) // setting the marker to be a square
15
            .colour("#DD3355"),
16
    ); // and a custom colour
17

18
    // The 'view' describes what set of data is drawn
19 1
    let v = ContinuousView::new()
20 1
        .add(s1)
21
        .x_range(-5., 10.)
22
        .y_range(-2., 6.)
23
        .x_label("Some varying variable")
24
        .y_label("The response of something");
25

26
    // A page with a single view is then saved to an SVG file
27 1
    Page::single(&v)
28
        .save("target/scatter_one_length.svg")
29
        .unwrap();
30
}
31

32
#[test]
33 1
fn test_data_with_no_length() {
34
    // Scatter plots expect a list of pairs
35 1
    let data1 = vec![];
36

37
    // We create our scatter plot from the data
38 1
    let s1 = Plot::new(data1).point_style(
39 1
        PointStyle::new()
40
            .marker(PointMarker::Square) // setting the marker to be a square
41
            .colour("#DD3355"),
42
    ); // and a custom colour
43

44
    // The 'view' describes what set of data is drawn
45 1
    let v = ContinuousView::new()
46 1
        .add(s1)
47
        .x_range(-5., 10.)
48
        .y_range(-2., 6.)
49
        .x_label("Some varying variable")
50
        .y_label("The response of something");
51

52
    // A page with a single view is then saved to an SVG file
53 1
    Page::single(&v)
54
        .save("target/scatter_zero_length.svg")
55
        .unwrap();
56
}
57

58
#[test]
59 1
fn test_data_with_one_length_and_autoscaling_axes_limits() {
60
    // Scatter plots expect a list of pairs
61 1
    let data1 = vec![(-3.0, 2.3)];
62

63
    // We create our scatter plot from the data
64 1
    let s1 = Plot::new(data1).point_style(
65 1
        PointStyle::new()
66
            .marker(PointMarker::Square) // setting the marker to be a square
67
            .colour("#DD3355"),
68
    ); // and a custom colour
69

70
    // The 'view' describes what set of data is drawn
71 1
    let v = ContinuousView::new()
72 1
        .add(s1)
73
        .x_label("Some varying variable")
74
        .y_label("The response of something");
75

76
    // // A page with a single view is then saved to an SVG file
77 1
    Page::single(&v)
78
        .save("target/scatter_one_length.svg")
79
        .unwrap();
80
}

Read our documentation on viewing source code .

Loading