@@ -862,8 +862,7 @@ def test_imshow():
862862
863863 # Reuse testcase from above for a labeled data test
864864 data = {"r" : r }
865- fig = plt .figure ()
866- ax = fig .add_subplot ()
865+ fig , ax = plt .subplots ()
867866 ax .imshow ("r" , data = data )
868867
869868
@@ -1335,8 +1334,7 @@ def test_markevery():
13351334 y = np .sin (x ) * np .sqrt (x / 10 + 0.5 )
13361335
13371336 # check marker only plot
1338- fig = plt .figure ()
1339- ax = fig .add_subplot ()
1337+ fig , ax = plt .subplots ()
13401338 ax .plot (x , y , 'o' , label = 'default' )
13411339 ax .plot (x , y , 'd' , markevery = None , label = 'mark all' )
13421340 ax .plot (x , y , 's' , markevery = 10 , label = 'mark every 10' )
@@ -1350,8 +1348,7 @@ def test_markevery_line():
13501348 y = np .sin (x ) * np .sqrt (x / 10 + 0.5 )
13511349
13521350 # check line/marker combos
1353- fig = plt .figure ()
1354- ax = fig .add_subplot ()
1351+ fig , ax = plt .subplots ()
13551352 ax .plot (x , y , '-o' , label = 'default' )
13561353 ax .plot (x , y , '-d' , markevery = None , label = 'mark all' )
13571354 ax .plot (x , y , '-s' , markevery = 10 , label = 'mark every 10' )
@@ -1465,8 +1462,7 @@ def test_markevery_polar():
14651462@image_comparison (['marker_edges' ], remove_text = True )
14661463def test_marker_edges ():
14671464 x = np .linspace (0 , 1 , 10 )
1468- fig = plt .figure ()
1469- ax = fig .add_subplot ()
1465+ fig , ax = plt .subplots ()
14701466 ax .plot (x , np .sin (x ), 'y.' , ms = 30.0 , mew = 0 , mec = 'r' )
14711467 ax .plot (x + 0.1 , np .sin (x ), 'y.' , ms = 30.0 , mew = 1 , mec = 'r' )
14721468 ax .plot (x + 0.2 , np .sin (x ), 'y.' , ms = 30.0 , mew = 2 , mec = 'b' )
@@ -1480,8 +1476,7 @@ def test_bar_tick_label_single():
14801476
14811477 # Reuse testcase from above for a labeled data test
14821478 data = {"a" : 0 , "b" : 1 }
1483- fig = plt .figure ()
1484- ax = fig .add_subplot ()
1479+ fig , ax = plt .subplots ()
14851480 ax = plt .gca ()
14861481 ax .bar ("a" , "b" , align = 'edge' , tick_label = '0' , data = data )
14871482
@@ -1683,8 +1678,7 @@ def test_pandas_minimal_plot(pd):
16831678def test_hist_log ():
16841679 data0 = np .linspace (0 , 1 , 200 )** 3
16851680 data = np .concatenate ([1 - data0 , 1 + data0 ])
1686- fig = plt .figure ()
1687- ax = fig .add_subplot ()
1681+ fig , ax = plt .subplots ()
16881682 ax .hist (data , fill = False , log = True )
16891683
16901684
@@ -1975,8 +1969,7 @@ def contour_dat():
19751969@image_comparison (['contour_hatching' ], remove_text = True , style = 'mpl20' )
19761970def test_contour_hatching ():
19771971 x , y , z = contour_dat ()
1978- fig = plt .figure ()
1979- ax = fig .add_subplot ()
1972+ fig , ax = plt .subplots ()
19801973 ax .contourf (x , y , z , 7 , hatches = ['/' , '\\ ' , '//' , '-' ],
19811974 cmap = plt .get_cmap ('gray' ),
19821975 extend = 'both' , alpha = 0.5 )
@@ -1989,8 +1982,7 @@ def test_contour_colorbar():
19891982
19901983 x , y , z = contour_dat ()
19911984
1992- fig = plt .figure ()
1993- ax = fig .add_subplot ()
1985+ fig , ax = plt .subplots ()
19941986 cs = ax .contourf (x , y , z , levels = np .arange (- 1.8 , 1.801 , 0.2 ),
19951987 cmap = plt .get_cmap ('RdBu' ),
19961988 vmin = - 0.6 ,
@@ -2017,14 +2009,12 @@ def test_hist2d():
20172009 # make it not symmetric in case we switch x and y axis
20182010 x = np .random .randn (100 )* 2 + 5
20192011 y = np .random .randn (100 )- 2
2020- fig = plt .figure ()
2021- ax = fig .add_subplot ()
2012+ fig , ax = plt .subplots ()
20222013 ax .hist2d (x , y , bins = 10 , rasterized = True )
20232014
20242015 # Reuse testcase from above for a labeled data test
20252016 data = {"x" : x , "y" : y }
2026- fig = plt .figure ()
2027- ax = fig .add_subplot ()
2017+ fig , ax = plt .subplots ()
20282018 ax .hist2d ("x" , "y" , bins = 10 , data = data , rasterized = True )
20292019
20302020
@@ -2038,8 +2028,7 @@ def test_hist2d_transpose():
20382028 # passing to pcolorfast
20392029 x = np .array ([5 ]* 100 )
20402030 y = np .random .randn (100 )- 2
2041- fig = plt .figure ()
2042- ax = fig .add_subplot ()
2031+ fig , ax = plt .subplots ()
20432032 ax .hist2d (x , y , bins = 10 , rasterized = True )
20442033
20452034
@@ -2877,8 +2866,7 @@ def test_boxplot_with_CIarray():
28772866
28782867 x = np .linspace (- 7 , 7 , 140 )
28792868 x = np .hstack ([- 25 , x , 25 ])
2880- fig = plt .figure ()
2881- ax = fig .add_subplot ()
2869+ fig , ax = plt .subplots ()
28822870 CIs = np .array ([[- 1.5 , 3. ], [- 1. , 3.5 ]])
28832871
28842872 # show a boxplot with Matplotlib medians and confidence intervals, and
@@ -3413,14 +3401,12 @@ def test_hist_stacked_stepfilled():
34133401 # make some data
34143402 d1 = np .linspace (1 , 3 , 20 )
34153403 d2 = np .linspace (0 , 10 , 50 )
3416- fig = plt .figure ()
3417- ax = fig .add_subplot ()
3404+ fig , ax = plt .subplots ()
34183405 ax .hist ((d1 , d2 ), histtype = "stepfilled" , stacked = True )
34193406
34203407 # Reuse testcase from above for a labeled data test
34213408 data = {"x" : (d1 , d2 )}
3422- fig = plt .figure ()
3423- ax = fig .add_subplot ()
3409+ fig , ax = plt .subplots ()
34243410 ax .hist ("x" , histtype = "stepfilled" , stacked = True , data = data )
34253411
34263412
@@ -3429,8 +3415,7 @@ def test_hist_offset():
34293415 # make some data
34303416 d1 = np .linspace (0 , 10 , 50 )
34313417 d2 = np .linspace (1 , 3 , 20 )
3432- fig = plt .figure ()
3433- ax = fig .add_subplot ()
3418+ fig , ax = plt .subplots ()
34343419 ax .hist (d1 , bottom = 5 )
34353420 ax .hist (d2 , bottom = 15 )
34363421
@@ -3439,8 +3424,7 @@ def test_hist_offset():
34393424def test_hist_step ():
34403425 # make some data
34413426 d1 = np .linspace (1 , 3 , 20 )
3442- fig = plt .figure ()
3443- ax = fig .add_subplot ()
3427+ fig , ax = plt .subplots ()
34443428 ax .hist (d1 , histtype = "step" )
34453429 ax .set_ylim (0 , 10 )
34463430 ax .set_xlim (- 1 , 5 )
@@ -3451,8 +3435,7 @@ def test_hist_step_horiz():
34513435 # make some data
34523436 d1 = np .linspace (0 , 10 , 50 )
34533437 d2 = np .linspace (1 , 3 , 20 )
3454- fig = plt .figure ()
3455- ax = fig .add_subplot ()
3438+ fig , ax = plt .subplots ()
34563439 ax .hist ((d1 , d2 ), histtype = "step" , orientation = "horizontal" )
34573440
34583441
@@ -3463,8 +3446,7 @@ def test_hist_stacked_weighted():
34633446 d2 = np .linspace (1 , 3 , 20 )
34643447 w1 = np .linspace (0.01 , 3.5 , 50 )
34653448 w2 = np .linspace (0.05 , 2. , 20 )
3466- fig = plt .figure ()
3467- ax = fig .add_subplot ()
3449+ fig , ax = plt .subplots ()
34683450 ax .hist ((d1 , d2 ), weights = (w1 , w2 ), histtype = "stepfilled" , stacked = True )
34693451
34703452
@@ -3521,8 +3503,7 @@ def test_hist_stacked_stepfilled_alpha():
35213503 # make some data
35223504 d1 = np .linspace (1 , 3 , 20 )
35233505 d2 = np .linspace (0 , 10 , 50 )
3524- fig = plt .figure ()
3525- ax = fig .add_subplot ()
3506+ fig , ax = plt .subplots ()
35263507 ax .hist ((d1 , d2 ), histtype = "stepfilled" , stacked = True , alpha = 0.5 )
35273508
35283509
@@ -3531,8 +3512,7 @@ def test_hist_stacked_step():
35313512 # make some data
35323513 d1 = np .linspace (1 , 3 , 20 )
35333514 d2 = np .linspace (0 , 10 , 50 )
3534- fig = plt .figure ()
3535- ax = fig .add_subplot ()
3515+ fig , ax = plt .subplots ()
35363516 ax .hist ((d1 , d2 ), histtype = "step" , stacked = True )
35373517
35383518
@@ -3549,8 +3529,7 @@ def test_hist_stacked_density():
35493529def test_hist_step_bottom ():
35503530 # make some data
35513531 d1 = np .linspace (1 , 3 , 20 )
3552- fig = plt .figure ()
3553- ax = fig .add_subplot ()
3532+ fig , ax = plt .subplots ()
35543533 ax .hist (d1 , bottom = np .arange (10 ), histtype = "stepfilled" )
35553534
35563535
@@ -3696,8 +3675,7 @@ def test_hist_stacked_bar():
36963675 (0.0 , 1.0 , 0.6549834156005998 ), (0.0 , 0.6569064625276622 , 1.0 ),
36973676 (0.28302699607823545 , 0.0 , 1.0 ), (0.6849123462299822 , 0.0 , 1.0 )]
36983677 labels = ['green' , 'orange' , ' yellow' , 'magenta' , 'black' ]
3699- fig = plt .figure ()
3700- ax = fig .add_subplot ()
3678+ fig , ax = plt .subplots ()
37013679 ax .hist (d , bins = 10 , histtype = 'barstacked' , align = 'mid' , color = colors ,
37023680 label = labels )
37033681 ax .legend (loc = 'upper right' , bbox_to_anchor = (1.0 , 1.0 ), ncol = 1 )
@@ -3710,8 +3688,7 @@ def test_hist_barstacked_bottom_unchanged():
37103688
37113689
37123690def test_hist_emptydata ():
3713- fig = plt .figure ()
3714- ax = fig .add_subplot ()
3691+ fig , ax = plt .subplots ()
37153692 ax .hist ([[], range (10 ), range (10 )], histtype = "step" )
37163693
37173694
@@ -3735,8 +3712,7 @@ def test_transparent_markers():
37353712 np .random .seed (0 )
37363713 data = np .random .random (50 )
37373714
3738- fig = plt .figure ()
3739- ax = fig .add_subplot ()
3715+ fig , ax = plt .subplots ()
37403716 ax .plot (data , 'D' , mfc = 'none' , markersize = 100 )
37413717
37423718
@@ -3814,8 +3790,7 @@ def test_alpha():
38143790 np .random .seed (0 )
38153791 data = np .random .random (50 )
38163792
3817- fig = plt .figure ()
3818- ax = fig .add_subplot ()
3793+ fig , ax = plt .subplots ()
38193794
38203795 # alpha=.5 markers, solid line
38213796 ax .plot (data , '-D' , color = [1 , 0 , 0 ], mfc = [1 , 0 , 0 , .5 ],
@@ -3978,8 +3953,7 @@ def test_eventplot_orientation(data, orientation):
39783953
39793954@image_comparison (['marker_styles.png' ], remove_text = True )
39803955def test_marker_styles ():
3981- fig = plt .figure ()
3982- ax = fig .add_subplot ()
3956+ fig , ax = plt .subplots ()
39833957 for y , marker in enumerate (sorted (matplotlib .markers .MarkerStyle .markers ,
39843958 key = lambda x : str (type (x ))+ str (x ))):
39853959 ax .plot ((y % 2 )* 5 + np .arange (10 )* 10 , np .ones (10 )* 10 * y , linestyle = '' ,
@@ -4001,8 +3975,7 @@ def test_vertex_markers():
40013975 data = list (range (10 ))
40023976 marker_as_tuple = ((- 1 , - 1 ), (1 , - 1 ), (1 , 1 ), (- 1 , 1 ))
40033977 marker_as_list = [(- 1 , - 1 ), (1 , - 1 ), (1 , 1 ), (- 1 , 1 )]
4004- fig = plt .figure ()
4005- ax = fig .add_subplot ()
3978+ fig , ax = plt .subplots ()
40063979 ax .plot (data , linestyle = '' , marker = marker_as_tuple , mfc = 'k' )
40073980 ax .plot (data [::- 1 ], linestyle = '' , marker = marker_as_list , mfc = 'b' )
40083981 ax .set_xlim ([- 1 , 10 ])
0 commit comments