@@ -2425,8 +2425,7 @@ def test_pyplot_axes():
2425
2425
2426
2426
@image_comparison (['log_scales' ])
2427
2427
def test_log_scales ():
2428
- fig = plt .figure ()
2429
- ax = fig .add_subplot (1 , 1 , 1 )
2428
+ fig , ax = plt .subplots ()
2430
2429
ax .plot (np .log (np .linspace (0.1 , 100 )))
2431
2430
ax .set_yscale ('log' , base = 5.5 )
2432
2431
ax .invert_yaxis ()
@@ -2441,8 +2440,7 @@ def test_log_scales_no_data():
2441
2440
2442
2441
2443
2442
def test_log_scales_invalid ():
2444
- fig = plt .figure ()
2445
- ax = fig .add_subplot (1 , 1 , 1 )
2443
+ fig , ax = plt .subplots ()
2446
2444
ax .set_xscale ('log' )
2447
2445
with pytest .warns (UserWarning , match = 'Attempted to set non-positive' ):
2448
2446
ax .set_xlim (- 1 , 10 )
@@ -2465,8 +2463,7 @@ def test_stackplot():
2465
2463
2466
2464
# Reuse testcase from above for a labeled data test
2467
2465
data = {"x" : x , "y1" : y1 , "y2" : y2 , "y3" : y3 }
2468
- fig = plt .figure ()
2469
- ax = fig .add_subplot (1 , 1 , 1 )
2466
+ fig , ax = plt .subplots ()
2470
2467
ax .stackplot ("x" , "y1" , "y2" , "y3" , data = data )
A3E2
2471
2468
ax .set_xlim ((0 , 10 ))
2472
2469
ax .set_ylim ((0 , 70 ))
@@ -3317,27 +3314,26 @@ def test_errorbar_limits():
3317
3314
yerr = 0.2
3318
3315
ls = 'dotted'
3319
3316
3320
- fig = plt .figure ()
3321
- ax = fig .add_subplot (1 , 1 , 1 )
3317
+ fig , ax = plt .subplots ()
3322
3318
3323
3319
# standard error bars
3324
- plt .errorbar (x , y , xerr = xerr , yerr = yerr , ls = ls , color = 'blue' )
3320
+ ax .errorbar (x , y , xerr = xerr , yerr = yerr , ls = ls , color = 'blue' )
3325
3321
3326
3322
# including upper limits
3327
3323
uplims = np .zeros_like (x )
3328
3324
uplims [[1 , 5 , 9 ]] = True
3329
- plt .errorbar (x , y + 0.5 , xerr = xerr , yerr = yerr , uplims = uplims , ls = ls ,
3330
- color = 'green' )
3325
+ ax .errorbar (x , y + 0.5 , xerr = xerr , yerr = yerr , uplims = uplims , ls = ls ,
3326
+ color = 'green' )
3331
3327
3332
3328
# including lower limits
3333
3329
lolims = np .zeros_like (x )
3334
3330
lolims [[2 , 4 , 8 ]] = True
3335
- plt .errorbar (x , y + 1.0 , xerr = xerr , yerr = yerr , lolims = lolims , ls = ls ,
3336
- color = 'red' )
3331
+ ax .errorbar (x , y + 1.0 , xerr = xerr , yerr = yerr , lolims = lolims , ls = ls ,
3332
+ color = 'red' )
3337
3333
3338
3334
# including upper and lower limits
3339
- plt .errorbar (x , y + 1.5 , marker = 'o' , ms = 8 , xerr = xerr , yerr = yerr ,
3340
- lolims = lolims , uplims = uplims , ls = ls , color = 'magenta' )
3335
+ ax .errorbar (x , y + 1.5 , marker = 'o' , ms = 8 , xerr = xerr , yerr = yerr ,
3336
+ lolims = lolims , uplims = uplims , ls = ls , color = 'magenta' )
3341
3337
3342
3338
# including xlower and xupper limits
3343
3339
xerr = 0.2
@@ -3349,10 +3345,10 @@ def test_errorbar_limits():
3349
3345
uplims = np .zeros_like (x )
3350
3346
lolims [[6 ]] = True
3351
3347
uplims [[3 ]] = True
3352
- plt .errorbar (x , y + 2.1 , marker = 'o' , ms = 8 , xerr = xerr , yerr = yerr ,
3353
- xlolims = xlolims , xuplims = xuplims , uplims = uplims ,
3354
- lolims = lolims , ls = 'none' , mec = 'blue' , capsize = 0 ,
3355
- color = 'cyan' )
3348
+ ax .errorbar (x , y + 2.1 , marker = 'o' , ms = 8 , xerr = xerr , yerr = yerr ,
3349
+ xlolims = xlolims , xuplims = xuplims , uplims = uplims ,
3350
+ lolims = lolims , ls = 'none' , mec = 'blue' , capsize = 0 ,
3351
+ color = 'cyan' )
3356
3352
ax .set_xlim ((0 , 5.5 ))
3357
3353
ax .set_title ('Errorbar upper and lower limits' )
3358
3354
@@ -3484,13 +3480,11 @@ def test_stem(use_line_collection):
3484
3480
ax .stem (x , np .cos (x ),
3485
3481
linefmt = 'C2-.' , markerfmt = 'k+' , basefmt = 'C1-.' , label = ' ' ,
3486
3482
use_line_collection = use_line_collection )
3487
-
3488
3483
ax .legend ()
3489
3484
3490
3485
3491
3486
def test_stem_args ():
3492
- fig = plt .figure ()
3493
- ax = fig .add_subplot (1 , 1 , 1 )
3487
+ fig , ax = plt .subplots ()
3494
3488
3495
3489
x = list (range (10 ))
3496
3490
10000
td> y = list (range (10 ))
@@ -4229,8 +4223,7 @@ def test_step_linestyle():
4229
4223
@image_comparison (['mixed_collection' ], remove_text = True )
4230
4224
def test_mixed_collection ():
4231
4225
# First illustrate basic pyplot interface, using defaults where possible.
4232
- fig = plt .figure ()
4233
- ax = fig .add_subplot (1 , 1 , 1 )
4226
+ fig , ax = plt .subplots ()
4234
4227
4235
4228
c = mpatches .Circle ((8 , 8 ), radius = 4 , facecolor = 'none' , edgecolor = 'green' )
4236
4229
@@ -4571,8 +4564,7 @@ def test_rcparam_grid_minor():
4571
4564
4572
4565
for locator , result in values :
4573
4566
matplotlib .rcParams ['axes.grid.which' ] = locator
4574
- fig = plt .figure ()
4575
- ax = fig .add_subplot (1 , 1 , 1 )
4567
+ fig , ax = plt .subplots ()
4576
4568
assert (ax .xaxis ._gridOnMajor , ax .xaxis ._gridOnMinor ) == result
4577
4569
4578
4570
matplotlib .rcParams ['axes.grid' ] = orig_grid
@@ -5786,16 +5778,14 @@ def test_title_no_move_off_page():
5786
5778
5787
5779
def test_offset_label_color ():
5788
5780
# Tests issue 6440
5789
- fig = plt .figure ()
5790
- ax = fig .add_subplot (1 , 1 , 1 )
5781
+ fig , ax = plt .subplots ()
5791
5782
ax .plot ([1.01e9 , 1.02e9 , 1.03e9 ])
5792
5783
ax .yaxis .set_tick_params (labelcolor = 'red' )
5793
5784
assert ax .yaxis .get_offset_text ().get_color () == 'red'
5794
5785
5795
5786
5796
5787
def test_offset_text_visible ():
5797
- fig = plt .figure ()
5798
- ax = fig .add_subplot (1 , 1 , 1 )
5788
+ fig , ax = plt .subplots ()
5799
5789
ax .plot ([1.01e9 , 1.02e9 , 1.03e9 ])
5800
5790
ax .yaxis .set_tick_params (label1On = False , label2On = True )
5801
5791
assert ax .yaxis .get_offset_text ().get_visible ()
0 commit comments