Skip to content

Commit cc99176

Browse files
committed
Add example output to readme
1 parent 8c9f04e commit cc99176

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,48 @@ plotlib
33

44
``plotlib`` is a generic data visualisation and plotting library for Rust.
55
It is currently in the very early stages of development.
6+
7+
It can currently produce scatter plot and histograms,
8+
rendering them as either SVG or plain text.
9+
10+
The API is still very much in flux and is subject to change.
11+
12+
For example, code like:
13+
14+
.. code-block:: rust
15+
16+
extern crate plotlib;
17+
use plotlib::scatter::Scatter;
18+
use plotlib::scatter;
19+
use plotlib::view::View;
20+
use plotlib::plot::Plot;
21+
22+
fn main() {
23+
// Scatter plots expect a list of pairs
24+
let data1 = [(-3.0, 2.3), (-1.6, 5.3), (0.3, 0.7), (4.3, -1.4), (6.4, 4.3), (8.5, 3.7)];
25+
// We create our scatter plot from the data
26+
let s1 = Scatter::from_vec(&data1)
27+
.style(scatter::Style::new()
28+
.marker(scatter::Marker::Square) // setting the marker to be a square
29+
.colour("#DD3355")); // and a custom colour
30+
31+
// We can plot multiple data sets in the same view
32+
let data2 = [(-1.4, 2.5), (7.2, -0.3)];
33+
let s2 = Scatter::from_vec(&data2)
34+
.style(scatter::Style::new() // uses the default marker
35+
.colour("#35C788")); // and a different colour
36+
37+
// The 'view' describeswhat set of data is drawn
38+
let v = View::new()
39+
.add(&s1)
40+
.add(&s2)
41+
.x_range(-5., 10.)
42+
.y_range(-2., 6.);
43+
44+
// A plot with a single view is then saved to an SVG file
45+
Plot::single(&v).save("scatter.svg");
46+
}
47+
48+
will produce output like:
49+
50+
.. figure:: scatter.png

scatter.png

3.91 KB
Loading

0 commit comments

Comments
 (0)