@@ -862,8 +862,7 @@ def test_imshow():
862
862
863
863
# Reuse testcase from above for a labeled data test
864
864
data = {"r" : r }
865
- fig = plt .figure ()
866
- ax = fig .add_subplot ()
865
+ fig , ax = plt .subplots ()
867
866
ax .imshow ("r" , data = data )
868
867
869
868
@@ -1335,8 +1334,7 @@ def test_markevery():
1335
1334
y = np .sin (x ) * np .sqrt (x / 10 + 0.5 )
1336
1335
1337
1336
# check marker only plot
1338
- fig = plt .figure ()
1339
- ax = fig .add_subplot ()
1337
+ fig , ax = plt .subplots ()
1340
1338
ax .plot (x , y , 'o' , label = 'default' )
1341
1339
ax .plot (x , y , 'd' , markevery = None , label = 'mark all' )
1342
1340
ax .plot (x , y , 's' , markevery = 10 , label = 'mark every 10' )
@@ -1350,8 +1348,7 @@ def test_markevery_line():
1350
1348
y = np .sin (x ) * np .sqrt (x / 10 + 0.5 )
1351
1349
1352
1350
# check line/marker combos
1353
- fig = plt .figure ()
1354
- ax = fig .add_subplot ()
1351
+ fig , ax = plt .subplots ()
1355
1352
ax .plot (x , y , '-o' , label = 'default' )
1356
1353
ax .plot (x , y , '-d' , markevery = None , label = 'mark all' )
1357
1354
ax .plot (x , y , '-s' , markevery = 10 , label = 'mark every 10' )
@@ -1465,8 +1462,7 @@ def test_markevery_polar():
1465
1462
@image_comparison (['marker_edges' ], remove_text = True )
1466
1463
def test_marker_edges ():
1467
1464
x = np .linspace (0 , 1 , 10 )
1468
- fig = plt .figure ()
1469
- ax = fig .add_subplot ()
1465
+ fig , ax = plt .subplots ()
1470
1466
ax .plot (x , np .sin (x ), 'y.' , ms = 30.0 , mew = 0 , mec = 'r' )
1471
1467
ax .plot (x + 0.1 , np .sin (x ), 'y.' , ms = 30.0 , mew = 1 , mec = 'r' )
1472
1468
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():
1480
1476
1481
1477
# Reuse testcase from above for a labeled data test
1482
1478
data = {"a" : 0 , "b" : 1 }
1483
- fig = plt .figure ()
1484
- ax = fig .add_subplot ()
1479
+ fig , ax = plt .subplots ()
1485
1480
ax = plt .gca ()
1486
1481
ax .bar ("a" , "b" , align = 'edge' , tick_label = '0' , data = data )
1487
1482
@@ -1683,8 +1678,7 @@ def test_pandas_minimal_plot(pd):
1683
1678
def test_hist_log ():
1684
1679
data0 = np .linspace (0 , 1 , 200 )** 3
1685
1680
data = np .concatenate ([1 - data0 , 1 + data0 ])
1686
- fig = plt .figure ()
1687
- ax = fig .add_subplot ()
1681
+ fig , ax = plt .subplots ()
1688
1682
ax .hist (data , fill = False , log = True )
1689
1683
1690
1684
@@ -1975,8 +1969,7 @@ def contour_dat():
1975
1969
@image_comparison (['contour_hatching' ], remove_text = True , style = 'mpl20' )
1976
1970
def test_contour_hatching ():
1977
1971
x , y , z = contour_dat ()
1978
- fig = plt .figure ()
1979
- ax = fig .add_subplot ()
1972
+ fig , ax = plt .subplots ()
1980
1973
ax .contourf (x , y , z , 7 , hatches = ['/' , '\\ ' , '//' , '-' ],
1981
1974
cmap = plt .get_cmap ('gray' ),
1982
1975
extend = 'both' , alpha = 0.5 )
@@ -1989,8 +1982,7 @@ def test_contour_colorbar():
1989
1982
1990
1983
x , y , z = contour_dat ()
1991
1984
1992
- fig = plt .figure ()
1993
- ax = fig .add_subplot ()
1985
+ fig , ax = plt .subplots ()
1994
1986
cs = ax .contourf (x , y , z , levels = np .arange (- 1.8 , 1.801 , 0.2 ),
1995
1987
cmap = plt .get_cmap ('RdBu' ),
1996
1988
vmin = - 0.6 ,
@@ -2017,14 +2009,12 @@ def test_hist2d():
2017
2009
# make it not symmetric in case we switch x and y axis
2018
2010
x = np .random .randn (100 )* 2 + 5
2019
2011
y = np .random .randn (100 )- 2
2020
- fig = plt .figure ()
2021
- ax = fig .add_subplot ()
2012
+ fig , ax = plt .subplots ()
2022
2013
ax .hist2d (x , y , bins = 10 , rasterized = True )
2023
2014
2024
2015
# Reuse testcase from above for a labeled data test
2025
2016
data = {"x" : x , "y" : y }
2026
- fig = plt .figure ()
2027
- ax = fig .add_subplot ()
2017
+ fig , ax = plt .subplots ()
2028
2018
ax .hist2d ("x" , "y" , bins = 10 , data = data , rasterized = True )
2029
2019
2030
2020
@@ -2038,8 +2028,7 @@ def test_hist2d_transpose():
2038
2028
# passing to pcolorfast
2039
2029
x = np .array ([5 ]* 100 )
2040
2030
y = np .random .randn (100 )- 2
2041
- fig = plt .figure ()
2042
- ax = fig .add_subplot ()
2031
+ fig , ax = plt .subplots ()
2043
2032
ax .hist2d (x , y , bins = 10 , rasterized = True )
2044
2033
2045
2034
@@ -2877,8 +2866,7 @@ def test_boxplot_with_CIarray():
2877
2866
2878
2867
x = np .linspace (- 7 , 7 , 140 )
2879
2868
x = np .hstack ([- 25 , x , 25 ])
2880
- fig = plt .figure ()
2881
- ax = fig .add_subplot ()
2869
+ fig , ax = plt .subplots ()
2882
2870
CIs = np .array ([[- 1.5 , 3. ], [- 1. , 3.5 ]])
2883
2871
2884
2872
# show a boxplot with Matplotlib medians and confidence intervals, and
@@ -3413,14 +3401,12 @@ def test_hist_stacked_stepfilled():
3413
3401
# make some data
3414
3402
d1 = np .linspace (1 , 3 , 20 )
3415
3403
d2 = np .linspace (0 , 10 , 50 )
3416
- fig = plt .figure ()
3417
- ax = fig .add_subplot ()
3404
+ fig , ax = plt .subplots ()
3418
3405
ax .hist ((d1 , d2 ), histtype = "stepfilled" , stacked = True )
3419
3406
3420
3407
# Reuse testcase from above for a labeled data test
3421
3408
data = {"x" : (d1 , d2 )}
3422
- fig = plt .figure ()
3423
- ax = fig .add_subplot ()
3409
+ fig , ax = plt .subplots ()
3424
3410
ax .hist ("x" , histtype = "stepfilled" , stacked = True , data = data )
3425
3411
3426
3412
@@ -3429,8 +3415,7 @@ def test_hist_offset():
3429
3415
# make some data
3430
3416
d1 = np .linspace (0 , 10 , 50 )
3431
3417
d2 = np .linspace (1 , 3 , 20 )
3432
- fig = plt .figure ()
3433
- ax = fig .add_subplot ()
3418
+ fig , ax = plt .subplots ()
3434
3419
ax .hist (d1 , bottom = 5 )
3435
3420
ax .hist (d2 , bottom = 15 )
3436
3421
@@ -3439,8 +3424,7 @@ def test_hist_offset():
3439
3424
def test_hist_step ():
3440
3425
# make some data
3441
3426
d1 = np .linspace (1 , 3 , 20 )
3442
- fig = plt .figure ()
3443
- ax = fig .add_subplot ()
3427
+ fig , ax = plt .subplots ()
3444
3428
ax .hist (d1 , histtype = "step" )
3445
3429
ax .set_ylim (0 , 10 )
3446
3430
ax .set_xlim (- 1 , 5 )
@@ -3451,8 +3435,7 @@ def test_hist_step_horiz():
3451
3435
# make some data
3452
3436
d1 = np .linspace (0 , 10 , 50 )
3453
3437
d2 = np .linspace (1 , 3 , 20 )
3454
- fig = plt .figure ()
3455
- ax = fig .add_subplot ()
3438
+ fig , ax = plt .subplots ()
3456
3439
ax .hist ((d1 , d2 ), histtype = "step" , orientation = "horizontal" )
3457
3440
3458
3441
@@ -3463,8 +3446,7 @@ def test_hist_stacked_weighted():
3463
3446
d2 = np .linspace (1 , 3 , 20 )
3464
3447
w1 = np .linspace (0.01 , 3.5 , 50 )
3465
3448
w2 = np .linspace (0.05 , 2. , 20 )
3466
- fig = plt .figure ()
3467
- ax = fig .add_subplot ()
3449
+ fig , ax = plt .subplots ()
3468
3450
ax .hist ((d1 , d2 ), weights = (w1 , w2 ), histtype = "stepfilled" , stacked = True )
3469
3451
3470
3452
@@ -3521,8 +3503,7 @@ def test_hist_stacked_stepfilled_alpha():
3521
3503
# make some data
3522
3504
d1 = np .linspace (1 , 3 , 20 )
3523
3505
d2 = np .linspace (0 , 10 , 50 )
3524
- fig = plt .figure ()
3525
- ax = fig .add_subplot ()
3506
+ fig , ax = plt .subplots ()
3526
3507
ax .hist ((d1 , d2 ), histtype = "stepfilled" , stacked = True , alpha = 0.5 )
3527
3508
3528
3509
@@ -3531,8 +3512,7 @@ def test_hist_stacked_step():
3531
3512
# make some data
3532
3513
d1 = np .linspace (1 , 3 , 20 )
3533
3514
d2 = np .linspace (0 , 10 , 50 )
3534
- fig = plt .figure ()
3535
- ax = fig .add_subplot ()
3515
+ fig , ax = plt .subplots ()
3536
3516
ax .hist ((d1 , d2 ), histtype = "step" , stacked = True )
3537
3517
3538
3518
@@ -3549,8 +3529,7 @@ def test_hist_stacked_density():
3549
3529
def test_hist_step_bottom ():
3550
3530
# make some data
3551
3531
d1 = np .linspace (1 , 3 , 20 )
3552
- fig = plt .figure ()
3553
- ax = fig .add_subplot ()
3532
+ fig , ax = plt .subplots ()
3554
3533
ax .hist (d1 , bottom = np .arange (10 ), histtype = "stepfilled" )
3555
3534
3556
3535
@@ -3696,8 +3675,7 @@ def test_hist_stacked_bar():
3696
3675
(0.0 , 1.0 , 0.6549834156005998 ), (0.0 , 0.6569064625276622 , 1.0 ),
3697
3676
(0.28302699607823545 , 0.0 , 1.0 ), (0.6849123462299822 , 0.0 , 1.0 )]
3698
3677
labels = ['green' , 'orange' , ' yellow' , 'magenta' , 'black' ]
3699
- fig = plt .figure ()
3700
- ax = fig .add_subplot ()
3678
+ fig , ax = plt .subplots ()
3701
3679
ax .hist (d , bins = 10 , histtype = 'barstacked' , align = 'mid' , color = colors ,
3702
3680
label = labels )
3703
3681
ax .legend (loc = 'upper right' , bbox_to_anchor = (1.0 , 1.0 ), ncol = 1 )
@@ -3710,8 +3688,7 @@ def test_hist_barstacked_bottom_unchanged():
3710
3688
3711
3689
3712
3690
def test_hist_emptydata ():
3713
- fig = plt .figure ()
3714
- ax = fig .add_subplot ()
3691
+ fig , ax = plt .subplots ()
3715
3692
ax .hist ([[], range (10 ), range (10 )], histtype = "step" )
3716
3693
3717
3694
@@ -3735,8 +3712,7 @@ def test_transparent_markers():
3735
3712
np .random .seed (0 )
3736
3713
data = np .random .random (50 )
3737
3714
3738
- fig = plt .figure ()
3739
- ax = fig .add_subplot ()
3715
+ fig , ax = plt .subplots ()
3740
3716
ax .plot (data , 'D' , mfc = 'none' , markersize = 100 )
3741
3717
3742
3718
@@ -3814,8 +3790,7 @@ def test_alpha():
3814
3790
np .random .seed (0 )
3815
3791
data = np .random .random (50 )
3816
3792
3817
- fig = plt .figure ()
3818
- ax = fig .add_subplot ()
3793
+ fig , ax = plt .subplots ()
3819
3794
3820
3795
# alpha=.5 markers, solid line
3821
3796
ax .plot (data , '-D' , color = [1 , 0 , 0 ], mfc = [1 , 0 , 0 , .5 ],
@@ -3978,8 +3953,7 @@ def test_eventplot_orientation(data, orientation):
3978
3953
3979
3954
@image_comparison (['marker_styles.png' ], remove_text = True )
3980
3955
def test_marker_styles ():
3981
- fig = plt .figure ()
3982
- ax = fig .add_subplot ()
3956
+ fig , ax = plt .subplots ()
3983
3957
for y , marker in enumerate (sorted (matplotlib .markers .MarkerStyle .markers ,
3984
3958
key = lambda x : str (type (x ))+ str (x ))):
3985
3959
ax .plot ((y % 2 )* 5 + np .arange (10 )* 10 , np .ones (10 )* 10 * y , linestyle = '' ,
@@ -4001,8 +3975,7 @@ def test_vertex_markers():
4001
3975
data = list (range (10 ))
4002
3976
marker_as_tuple = ((- 1 , - 1 ), (1 , - 1 ), (1 , 1 ), (- 1 , 1 ))
4003
3977
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 ()
4006
3979
ax .plot (data , linestyle = '' , marker = marker_as_tuple , mfc = 'k' )
4007
3980
ax .plot (data [::- 1 ], linestyle = '' , marker = marker_as_list , mfc = 'b' )
4008
3981
ax .set_xlim ([- 1 , 10 ])
0 commit comments