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 2
fn test_data_with_one_length() {
8
    // Scatter plots expect a list of pairs
9 2
    let data1 = vec![(-3.0, 2.3)];
10

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

18
    // The 'view' describes what set of data is drawn
19 2
    let v = ContinuousView::new()
20 2
        .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 2
    Page::single(&v)
28
        .save("/tmp/scatter_one_length.svg")
29
        .unwrap();
30
}
31

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

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

44
    // The 'view' describes what set of data is drawn
45 2
    let v = ContinuousView::new()
46 2
        .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 2
    Page::single(&v)
54
        .save("/tmp/scatter_zero_length.svg")
55
        .unwrap();
56
}
57

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

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

70
    // The 'view' describes what set of data is drawn
71 2
    let v = ContinuousView::new()
72 2
        .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 2
    Page::single(&v)
78
        .save("/tmp/scatter_one_length.svg")
79
        .unwrap();
80
}

Read our documentation on viewing source code .

Loading