@@ -489,6 +489,20 @@ def test_autoscale_tight():
489
489
assert_allclose (ax .get_xlim (), (- 0.15 , 3.15 ))
490
490
assert_allclose (ax .get_ylim (), (1.0 , 4.0 ))
491
491
492
+ # Check that autoscale is on
493
+ assert ax .get_autoscalex_on ()
494
+ assert ax .get_autoscaley_on ()
495
+ assert ax .get_autoscale_on ()
496
+ # Set enable to None
497
+ ax .autoscale (enable = None )
498
+ # Same limits
499
+ assert_allclose (ax .get_xlim (), (- 0.15 , 3.15 ))
500
+ assert_allclose (ax .get_ylim (), (1.0 , 4.0 ))
501
+ # autoscale still on
502
+ assert ax .get_autoscalex_on ()
503
+ assert ax .get_autoscaley_on ()
504
+ assert ax .get_autoscale_on ()
505
+
492
506
493
507
@mpl .style .context ('default' )
494
508
def test_autoscale_log_shared ():
@@ -4982,6 +4996,23 @@ def test_shared_aspect_error():
4982
4996
fig .draw_without_rendering ()
4983
4997
4984
4998
4999
+ @pytest .mark .parametrize ('err, args, kwargs, match' ,
5000
+ ((TypeError , (1 , 2 ), {},
5001
+ r"axis\(\) takes 0 or 1 positional arguments but 2"
5002
+ " were given" ),
5003
+ (ValueError , ('foo' , ), {},
5004
+ "Unrecognized string foo to axis; try on or off" ),
5005
+ (TypeError , ([1 , 2 ], ), {},
5006
+ "the first argument to axis*" ),
5007
+ (TypeError , tuple (), {'foo' : None },
5008
+ r"axis\(\) got an unexpected keyword argument "
5009
+ "'foo'" ),
5010
+ ))
5011
+ def test_axis_errors (err , args , kwargs , match ):
5012
+ with pytest .raises (err , match = match ):
5013
+ plt .axis (* args , ** kwargs )
5014
+
5015
+
4985
5016
@pytest .mark .parametrize ('twin' , ('x' , 'y' ))
4986
5017
def test_twin_with_aspect (twin ):
4987
5018
fig , ax = plt .subplots ()
@@ -5375,12 +5406,58 @@ def test_set_margin_updates_limits():
5375
5406
assert ax .get_xlim () == (1 , 2 )
5376
5407
5377
5408
5409
+ @pytest .mark .parametrize ('err, args, kwargs, match' ,
5410
+ ((ValueError , (- 1 ,), {},
5411
+ 'margin must be greater than -0.5' ),
5412
+ (ValueError , (1 , - 1 ), {},
5413
+ 'margin must be greater than -0.5' ),
5414
+ (ValueError , tuple (), {'x' : - 1 },
5415
+ 'margin must be greater than -0.5' ),
5416
+ (ValueError , tuple (), {'y' : - 1 },
5417
+ 'margin must be greater than -0.5' ),
5418
+ (TypeError , (1 , ), {'x' : 1 , 'y' : 1 },
5419
+ 'Cannot pass both positional and keyword '
5420
+ 'arguments for x and/or y.' ),
5421
+ (TypeError , (1 , 1 , 1 ), {},
5422
+ 'Must pass a single positional argument for all*' ),
5423
+ ))
5424
+ def test_margins_errors (err , args , kwargs , match ):
5425
+ with pytest .raises (err , match = match ):
5426
+ fig = plt .figure ()
5427
+ ax = fig .add_subplot ()
5428
+ ax .margins (* args , ** kwargs )
5429
+
5430
+
5378
5431
def test_length_one_hist ():
5379
5432
fig , ax = plt .subplots ()
5380
5433
ax .hist (1 )
5381
5434
ax .hist ([1 ])
5382
5435
5383
5436
5437
+ def test_set_xy_bound ():
5438
+ fig = plt .figure ()
5439
+ ax = fig .add_subplot ()
5440
+ ax .set_xbound (2.0 , 3.0 )
5441
+ assert ax .get_xbound () == (2.0 , 3.0 )
5442
+ assert ax .get_xlim () == (2.0 , 3.0 )
5443
+ ax .set_xbound (upper = 4.0 )
5444
+ assert ax .get_xbound () == (2.0 , 4.0 )
5445
+ assert ax .get_xlim () == (2.0 , 4.0 )
5446
+ ax .set_xbound (lower = 3.0 )
5447
+ assert ax .get_xbound () == (3.0 , 4.0 )
5448
+ assert ax .get_xlim () == (3.0 , 4.0 )
5449
+
5450
+ ax .set_ybound (2.0 , 3.0 )
5451
+ assert ax .get_ybound () == (2.0 , 3.0 )
5452
+ assert ax .get_ylim () == (2.0 , 3.0 )
5453
+ ax .set_ybound (upper = 4.0 )
5454
+ assert ax .get_ybound () == (2.0 , 4.0 )
5455
+ assert ax .get_ylim () == (2.0 , 4.0 )
5456
+ ax .set_ybound (lower = 3.0 )
5457
+ assert ax .get_ybound () == (3.0 , 4.0 )
5458
+ assert ax .get_ylim () == (3.0 , 4.0 )
5459
+
5460
+
5384
5461
def test_pathological_hexbin ():
5385
5462
# issue #2863
5386
5463
mylist = [10 ] * 100
@@ -6067,6 +6144,7 @@ def test_axisbelow():
6067
6144
left = False , right = False )
6068
6145
ax .spines [:].set_visible (False )
6069
6146
ax .set_axisbelow (setting )
6147
+ assert ax .get_axisbelow () == setting
6070
6148
6071
6149
6072
6150
def test_titletwiny ():
@@ -6613,6 +6691,12 @@ def test_secondary_formatter():
6613
6691
secax .xaxis .get_major_formatter (), mticker .ScalarFormatter )
6614
6692
6615
6693
6694
+ def test_secondary_repr ():
6695
+ fig , ax = plt .subplots ()
6696
+ secax = ax .secondary_xaxis ("top" )
6697
+ assert repr (secax ) == '<SecondaryAxis:>'
6698
+
6699
+
6616
6700
def color_boxes (fig , ax ):
6617
6701
"""
6618
6702
Helper for the tests below that test the extents of various axes elements
@@ -6836,6 +6920,23 @@ def test_axis_extent_arg():
6836
6920
assert (ymin , ymax ) == ax .get_ylim ()
6837
6921
6838
6922
6923
+ def test_axis_extent_arg2 ():
6924
+ # Same as test_axis_extent_arg, but with keyword arguments
6925
+ fig , ax = plt .subplots ()
6926
+ xmin = 5
6927
+ xmax = 10
6928
+ ymin = 15
6929
+ ymax = 20
6930
+ extent = ax .axis (xmin = xmin , xmax = xmax , ymin = ymin , ymax = ymax )
6931
+
6932
+ # test that the docstring is correct
6933
+ assert tuple (extent ) == (xmin , xmax , ymin , ymax )
6934
+
6935
+ # test that limits were set per the docstring
6936
+ assert (xmin , xmax ) == ax .get_xlim ()
6937
+ assert (ymin , ymax ) == ax .get_ylim ()
6938
+
6939
+
6839
6940
def test_datetime_masked ():
6840
6941
# make sure that all-masked data falls back to the viewlim
6841
6942
# set in convert.axisinfo....
0 commit comments