11use plotlib:: page:: Page ;
22use plotlib:: repr:: Plot ;
3- use plotlib:: style:: { PointMarker , PointStyle } ;
43use plotlib:: view:: ContinuousView ;
4+ use plotlib:: style:: { PointMarker , PointStyle } ;
55
66fn 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+ }
0 commit comments