11/// Inspired from
22/// https://matplotlib.org/stable/plot_types/index.html#plot-types
3- use matplotlib:: { colors:: Base , self as mpl, figure:: Figure } ;
3+ use matplotlib:: { colors:: Base , self as mpl, figure} ;
44use ndarray:: Array1 ;
55use rand:: RngExt ;
66
@@ -25,8 +25,7 @@ fn plot_xy() -> anyhow::Result<()> {
2525 let x2: Vec < _ > = ( 0 ..25 ) . map ( |i| 10. / 25. * i as f64 ) . collect ( ) ;
2626 let y2 = x2. iter ( ) . cloned ( ) . map ( f) ;
2727
28- let fig = Figure :: new ( ) ?;
29- let [ [ mut ax] ] = fig. subplots ( ) ?;
28+ let ( fig, [ [ mut ax] ] ) = figure:: subplots ( ) ?;
3029
3130 let y2_above: Vec < _ > = y2. clone ( ) . map ( |y| y + 2.5 ) . collect ( ) ;
3231 ax. xy ( & x2, & y2_above) . fmt ( "x" ) . markeredgewidth ( 2. ) . plot ( ) ;
@@ -55,8 +54,7 @@ fn scatter_xy() -> anyhow::Result<()> {
5554 let sizes = vec ( || rng. random_range ( 15. .. 80. ) ) ;
5655 let colors = vec ( || rng. random_range ( 15 .. 80 ) ) ;
5756
58- let fig = Figure :: new ( ) ?;
59- let [ [ mut ax] ] = fig. subplots ( ) ?;
57+ let ( fig, [ [ mut ax] ] ) = figure:: subplots ( ) ?;
6058
6159 ax. scatter ( & x, & y) . s ( & sizes) . cm ( & colors) . vmin ( 0. ) . vmax ( 100. ) . plot ( ) ;
6260
@@ -70,8 +68,7 @@ fn bar() -> anyhow::Result<()> {
7068 let x: Vec < _ > = ( 0 .. 8 ) . map ( |x| 0.5 + x as f64 ) . collect ( ) ;
7169 let y = [ 4.8 , 5.5 , 3.5 , 4.6 , 6.5 , 6.6 , 2.6 , 3.0 ] ;
7270
73- let fig = Figure :: new ( ) ?;
74- let [ [ mut ax] ] = fig. subplots ( ) ?;
71+ let ( fig, [ [ mut ax] ] ) = figure:: subplots ( ) ?;
7572
7673 ax. bar ( & x, & y) . width ( 1. ) . edgecolor ( Base :: W ) . linewidth ( 0.7 ) . plot ( ) ;
7774
@@ -85,8 +82,7 @@ fn stem() -> anyhow::Result<()> {
8582 let x = Array1 :: range ( 0.5 , 8.5 , 1. ) ;
8683 let y = [ 4.8 , 5.5 , 3.5 , 4.6 , 6.5 , 6.6 , 2.6 , 3.0 ] ;
8784
88- let fig = Figure :: new ( ) ?;
89- let [ [ mut ax] ] = fig. subplots ( ) ?;
85+ let ( fig, [ [ mut ax] ] ) = figure:: subplots ( ) ?;
9086
9187 ax. stem ( & x, & y) . plot ( ) ;
9288
@@ -102,8 +98,7 @@ fn fill_between() -> anyhow::Result<()> {
10298 let y1 = x. map ( |& x| 3. + 4. * x / 8. + rng. random_range ( 0. .. 0.5 ) ) ;
10399 let y2 = x. map ( |& x| 1. + 2. * x / 8. + rng. random_range ( 0. .. 0.5 ) ) ;
104100
105- let fig = Figure :: new ( ) ?;
106- let [ [ mut ax] ] = fig. subplots ( ) ?;
101+ let ( fig, [ [ mut ax] ] ) = figure:: subplots ( ) ?;
107102
108103 ax. fill_between ( & x, & y1, & y2) . alpha ( 0.5 ) . plot ( ) ;
109104 ax. xy ( & x, & ( ( y1 + y2) / 2. ) ) . plot ( ) ;
0 commit comments