@@ -488,6 +488,20 @@ def test_autoscale_tight():
488
488
assert_allclose (ax .get_xlim (), (- 0.15 , 3.15 ))
489
489
assert_allclose (ax .get_ylim (), (1.0 , 4.0 ))
490
490
491
+ # Check that autoscale is on
492
+ assert ax .get_autoscalex_on ()
493
+ assert ax .get_autoscaley_on ()
494
+ assert ax .get_autoscale_on ()
495
+ # Set enable to None
496
+ ax .autoscale (enable = None )
497
+ # Same limits
498
+ assert_allclose (ax .get_xlim (), (- 0.15 , 3.15 ))
499
+ assert_allclose (ax .get_ylim (), (1.0 , 4.0 ))
500
+ # autoscale still on
501
+ assert ax .get_autoscalex_on ()
502
+ assert ax .get_autoscaley_on ()
503
+ assert ax .get_autoscale_on ()
504
+
491
505
492
506
@mpl .style .context ('default' )
493
507
def test_autoscale_log_shared ():
@@ -4949,6 +4963,23 @@ def test_shared_with_aspect_3():
4949
4963
assert round (expected , 4 ) == round (ax .get_aspect (), 4 )
4950
4964
4951
4965
4966
+ @pytest .mark .parametrize ('err, args, kwargs, match' ,
4967
+ ((TypeError , (1 , 2 ), {},
4968
+ r"axis\(\) takes 0 or 1 positional arguments but 2"
4969
+ " were given" ),
4970
+ (ValueError , ('foo' , ), {},
4971
+ "Unrecognized string foo to axis; try on or off" ),
4972
+ (TypeError , ([1 , 2 ], ), {},
4973
+ "the first argument to axis*" ),
4974
+ (TypeError , tuple (), {'foo' : None },
4975
+ r"axis\(\) got an unexpected keyword argument "
4976
+ "'foo'" ),
4977
+ ))
4978
+ def test_axis_errors (err , args , kwargs , match ):
4979
+ with pytest .raises (err , match = match ):
4980
+ plt .axis (* args , ** kwargs )
4981
+
4982
+
4952
4983
@pytest .mark .parametrize ('twin' , ('x' , 'y' ))
4953
4984
def test_twin_with_aspect (twin ):
4954
4985
fig , ax = plt .subplots ()
@@ -5342,12 +5373,58 @@ def test_set_margin_updates_limits():
5342
5373
assert ax .get_xlim () == (1 , 2 )
5343
5374
5344
5375
5376
+ @pytest .mark .parametrize ('err, args, kwargs, match' ,
5377
+ ((ValueError , (- 1 ,), {},
5378
+ 'margin must be greater than -0.5' ),
5379
+ (ValueError , (1 , - 1 ), {},
5380
+ 'margin must be greater than -0.5' ),
5381
+ (ValueError , tuple (), {'x' : - 1 },
5382
+ 'margin must be greater than -0.5' ),
5383
+ (ValueError , tuple (), {'y' : - 1 },
5384
+ 'margin must be greater than -0.5' ),
5385
+ (TypeError , (1 , ), {'x' : 1 , 'y' : 1 },
5386
+ 'Cannot pass both positional and keyword '
5387
+ 'arguments for x and/or y.' ),
5388
+ (TypeError , (1 , 1 , 1 ), {},
5389
+ 'Must pass a single positional argument for all*' ),
5390
+ ))
5391
+ def test_margins_errors (err , args , kwargs , match ):
5392
+ with pytest .raises (err , match = match ):
5393
+ fig = plt .figure ()
5394
+ ax = fig .add_subplot ()
5395
+ ax .margins (* args , ** kwargs )
5396
+
5397
+
5345
5398
def test_length_one_hist ():
5346
5399
fig , ax = plt .subplots ()
5347
5400
ax .hist (1 )
5348
5401
ax .hist ([1 ])
5349
5402
5350
5403
5404
+ def test_set_xy_bound ():
5405
+ fig = plt .figure ()
5406
+ ax = fig .add_subplot ()
5407
+ ax .set_xbound (2.0 , 3.0 )
5408
+ assert ax .get_xbound () == (2.0 , 3.0 )
5409
+ assert ax .get_xlim () == (2.0 , 3.0 )
5410
+ ax .set_xbound (upper = 4.0 )
5411
+ assert ax .get_xbound () == (2.0 , 4.0 )
5412
+ assert ax .get_xlim () == (2.0 , 4.0 )
5413
+ ax .set_xbound (lower = 3.0 )
5414
+ assert ax .get_xbound () == (3.0 , 4.0 )
5415
+ assert ax .get_xlim () == (3.0 , 4.0 )
5416
+
5417
+ ax .set_ybound (2.0 , 3.0 )
5418
+ assert ax .get_ybound () == (2.0 , 3.0 )
5419
+ assert ax .get_ylim () == (2.0 , 3.0 )
5420
+ ax .set_ybound (upper = 4.0 )
5421
+ assert ax .get_ybound () == (2.0 , 4.0 )
5422
+ assert ax .get_ylim () == (2.0 , 4.0 )
5423
+ ax .set_ybound (lower = 3.0 )
5424
+ assert ax .get_ybound () == (3.0 , 4.0 )
5425
+ assert ax .get_ylim () == (3.0 , 4.0 )
5426
+
5427
+
5351
5428
def test_pathological_hexbin ():
5352
5429
# issue #2863
5353
5430
mylist = [10 ] * 100
@@ -6020,6 +6097,7 @@ def test_axisbelow():
6020
6097
left = False , right = False )
6021
6098
ax .spines [:].set_visible (False )
6022
6099
ax .set_axisbelow (setting )
6100
+ assert ax .get_axisbelow () == setting
6023
6101
6024
6102
6025
6103
def test_titletwiny ():
@@ -6536,6 +6614,12 @@ def test_secondary_formatter():
6536
6614
secax .xaxis .get_major_formatter (), mticker .ScalarFormatter )
6537
6615
6538
6616
6617
+ def test_secondary_repr ():
6618
+ fig , ax = plt .subplots ()
6619
+ secax = ax .secondary_xaxis ("top" )
6620
+ assert repr (secax ) == '<SecondaryAxis:>'
6621
+
6622
+
6539
6623
def color_boxes (fig , ax ):
6540
6624
"""
6541
6625
Helper for the tests below that test the extents of various axes elements
@@ -6759,6 +6843,23 @@ def test_axis_extent_arg():
6759
6843
assert (ymin , ymax ) == ax .get_ylim ()
6760
6844
6761
6845
6846
+ def test_axis_extent_arg2 ():
6847
+ # Same as test_axis_extent_arg, but with keyword arguments
6848
+ fig , ax = plt .subplots ()
6849
+ xmin = 5
6850
+ xmax = 10
6851
+ ymin = 15
6852
+ ymax = 20
81E4
6853
+ extent = ax .axis (xmin = xmin , xmax = xmax , ymin = ymin , ymax = ymax )
6854
+
6855
+ # test that the docstring is correct
6856
+ assert tuple (extent ) == (xmin , xmax , ymin , ymax )
6857
+
6858
+ # test that limits were set per the docstring
6859
+ assert (xmin , xmax ) == ax .get_xlim ()
6860
+ assert (ymin , ymax ) == ax .get_ylim ()
6861
+
6862
+
6762
6863
def test_datetime_masked ():
6763
6864
# make sure that all-masked data falls back to the viewlim
6764
6865
# set in convert.axisinfo....
0 commit comments