Skip to content

Commit 0e80bb1

Browse files
committed
Update example in readme
1 parent 6cbe669 commit 0e80bb1

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ For example, code like:
2424

2525
```rust
2626
use plotlib::page::Page;
27-
use plotlib::repr::Scatter;
27+
use plotlib::repr::Plot;
2828
use plotlib::view::ContinuousView;
2929
use plotlib::style::{PointMarker, PointStyle};
3030

3131
fn main() {
3232
// Scatter plots expect a list of pairs
33-
let data1 = [
33+
let data1 = vec![
3434
(-3.0, 2.3),
3535
(-1.6, 5.3),
3636
(0.3, 0.7),
@@ -40,15 +40,15 @@ fn main() {
4040
];
4141

4242
// We create our scatter plot from the data
43-
let s1: Scatter = Scatter::from_slice(&data1).style(
43+
let s1: Plot = Plot::new(data1).point_style(
4444
PointStyle::new()
4545
.marker(PointMarker::Square) // setting the marker to be a square
4646
.colour("#DD3355"),
4747
); // and a custom colour
4848

4949
// We can plot multiple data sets in the same view
50-
let data2 = [(-1.4, 2.5), (7.2, -0.3)];
51-
let s2: Scatter = Scatter::from_slice(&data2).style(
50+
let data2 = vec![(-1.4, 2.5), (7.2, -0.3)];
51+
let s2: Plot = Plot::new(data2).point_style(
5252
PointStyle::new() // uses the default marker
5353
.colour("#35C788"),
5454
); // and a different colour

examples/scatter_svg.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
use plotlib::page::Page;
22
use plotlib::repr::Plot;
3-
use plotlib::style::{PointMarker, PointStyle};
43
use plotlib::view::ContinuousView;
4+
use plotlib::style::{PointMarker, PointStyle};
55

66
fn main() {
7-
let data = vec![
7+
// Scatter plots expect a list of pairs
8+
let data1 = vec![
89
(-3.0, 2.3),
910
(-1.6, 5.3),
1011
(0.3, 0.7),
1112
(4.3, -1.4),
1213
(6.4, 4.3),
1314
(8.5, 3.7),
1415
];
15-
let s1 = Plot::new(data).point_style(
16+
17+
// We create our scatter plot from the data
18+
let s1: Plot = Plot::new(data1).point_style(
1619
PointStyle::new()
17-
.marker(PointMarker::Square)
18-
.colour("burlywood")
19-
.size(2.),
20-
);
21-
let s2 = Plot::new(vec![(-1.4, 2.5), (7.2, -0.3)])
22-
.point_style(PointStyle::new().colour("darkseagreen"));
20+
.marker(PointMarker::Square) // setting the marker to be a square
21+
.colour("#DD3355"),
22+
); // and a custom colour
23+
24+
// We can plot multiple data sets in the same view
25+
let data2 = vec![(-1.4, 2.5), (7.2, -0.3)];
26+
let s2: Plot = Plot::new(data2).point_style(
27+
PointStyle::new() // uses the default marker
28+
.colour("#35C788"),
29+
); // and a different colour
2330

31+
// The 'view' describes what set of data is drawn
2432
let v = ContinuousView::new()
2533
.add(s1)
2634
.add(s2)
@@ -29,5 +37,6 @@ fn main() {
2937
.x_label("Some varying variable")
3038
.y_label("The response of something");
3139

32-
Page::single(&v).save("scatter.svg").expect("saving svg");
33-
}
40+
// A page with a single view is then saved to an SVG file
41+
Page::single(&v).save("scatter.svg").unwrap();
42+
}

scatter.png

236 Bytes
Loading

0 commit comments

Comments
 (0)