@@ -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 ():
@@ -4947,6 +4961,23 @@ def test_shared_with_aspect_3():
4947
4961
assert round (expected , 4 ) == round (ax .get_aspect (), 4 )
4948
4962
4949
4963
4964
+ @pytest .mark .parametrize ('err, args, kwargs, match' ,
4965
+ ((TypeError , (1 , 2 ), {},
4966
+ r"axis\(\) takes 0 or 1 positional arguments but 2"
4967
+ " were given" ),
4968
+ (ValueError , ('foo' , ), {},
4969
+ "Unrecognized string foo to axis; try on or off" ),
4970
+ (TypeError , ([1 , 2 ], ), {},
4971
+ "the first argument to axis*" ),
4972
+ (TypeError , tuple (), {'foo' : None },
4973
+ r"axis\(\) got an unexpected keyword argument "
4974
+ "'foo'" ),
4975
+ ))
4976
+ def test_axis_errors (err , args , kwargs , match ):
4977
+ with pytest .raises (err , match = match ):
4978
+ plt .axis (* args , ** kwargs )
4979
+
4980
+
4950
4981
@pytest .mark .parametrize ('twin' , ('x' , 'y' ))
4951
4982
def test_twin_with_aspect (twin ):
4952
4983
fig , ax = plt .subplots ()
@@ -5340,12 +5371,58 @@ def test_set_margin_updates_limits():
5340
5371
assert ax .get_xlim () == (1 , 2 )
5341
5372
5342
5373
5374
+ @pytest .mark .parametrize ('err, args, kwargs, match' ,
5375
+ ((ValueError , (- 1 ,), {},
5376
+ 'margin must be greater than -0.5' ),
5377
+ (ValueError , (1 , - 1 ), {},
5378
+ 'margin must be greater than -0.5' ),
5379
+ (ValueError , tuple (), {'x' : - 1 },
5380
+ 'margin must be greater than -0.5' ),
5381
+ (ValueError , tuple (), {'y' : - 1 },
5382
+ 'margin must be greater than -0.5' ),
5383
+ (TypeError , (1 , ), {'x' : 1 , 'y' : 1 },
5384
+ 'Cannot pass both positional and keyword '
5385
+ 'arguments for x and/or y.' ),
5386
+ (TypeError , (1 , 1 , 1 ), {},
5387
+ 'Must pass a single positional argument for all*' ),
5388
+ ))
5389
+ def test_margins_errors (err , args , kwargs , match ):
5390
+ with pytest .raises (err , match = match ):
5391
+ fig = plt .figure ()
5392
+ ax = fig .add_subplot ()
5393
+ ax .margins (* args , ** kwargs )
5394
+
5395
+
5343
5396
def test_length_one_hist ():
5344
5397
fig , ax = plt .subplots ()
5345
5398
ax .hist (1 )
5346
5399
ax .hist ([1 ])
5347
5400
5348
5401
5402
+ def test_set_xy_bound ():
5403
+ fig = plt .figure ()
5404
+ ax = fig .add_subplot ()
5405
+ ax .set_xbound (2.0 , 3.0 )
5406
+ assert ax .get_xbound () == (2.0 , 3.0 )
5407
+ assert ax .get_xlim () == (2.0 , 3.0 )
5408
+ ax .set_xbound (upper = 4.0 )
5409
+ assert ax .get_xbound () == (2.0 , 4.0 )
5410
+ assert ax .get_xlim () == (2.0 , 4.0 )
5411
+ ax .set_xbound (lower = 3.0 )
5412
+ assert ax .get_xbound () == (3.0 , 4.0 )
5413
+ assert ax .get_xlim () == (3.0 , 4.0 )
5414 +
5415
+ ax .set_ybound (2.0 , 3.0 )
5416
+ assert ax .get_ybound () == (2.0 , 3.0 )
5417
+ assert ax .get_ylim () == (2.0 , 3.0 )
5418
+ ax .set_ybound (upper = 4.0 )
5419
+ assert ax .get_ybound () == (2.0 , 4.0 )
5420
+ assert ax .get_ylim () == (2.0 , 4.0 )
5421
+ ax .set_ybound (lower = 3.0 )
5422
+ assert ax .get_ybound () == (3.0 , 4.0 )
5423
+ assert ax .get_ylim () == (3.0 , 4.0 )
5424
+
5425
+
5349
5426
def test_pathological_hexbin ():
5350
5427
# issue #2863
5351
5428
mylist = [10 ] * 100
@@ -6018,6 +6095,7 @@ def test_axisbelow():
6018
6095
left = False , right = False )
6019
6096
ax .spines [:].set_visible (False )
6020
6097
ax .set_axisbelow (setting )
6098
+ assert ax .get_axisbelow () == setting
6021
6099
6022
6100
6023
6101
def test_titletwiny ():
@@ -6534,6 +6612,12 @@ def test_secondary_formatter():
6534
6612
secax .xaxis .get_major_formatter (), mticker .ScalarFormatter )
6535
6613
6536
6614
6615
+ def test_secondary_repr ():
6616
+ fig , ax = plt .subplots ()
6617
+ secax = ax .secondary_xaxis ("top" )
6618
+ assert repr (secax ) == '<SecondaryAxis:>'
6619
+
6620
+
6537
6621
def color_boxes (fig , ax ):
6538
6622
"""
6539
6623
Helper for the tests below that test the extents of various axes elements
@@ -6757,6 +6841,23 @@ def test_axis_extent_arg():
6757
6841
assert (ymin , ymax ) == ax .get_ylim ()
6758
6842
6759
6843
6844
+ def test_axis_extent_arg2 ():
6845
+ # Same as test_axis_extent_arg, but with keyword arguments
6846
+ fig , ax = plt .subplots ()
6847
+ xmin = 5
6848
+ xmax = 10
6849
+ ymin = 15
6850
+ ymax = 20
6851
+ extent = ax .axis (xmin = xmin , xmax = xmax , ymin = ymin , ymax = ymax )
6852
+
6853
+ # test that the docstring is correct
6854
+ assert tuple (extent ) == (xmin , xmax , ymin , ymax )
6855
+
6856
+ # test that limits were set per the docstring
6857
+ assert (xmin , xmax ) == ax .get_xlim ()
6858
+ assert (ymin , ymax ) == ax .get_ylim ()
6859
+
6860
+
6760
6861
def test_datetime_masked ():
6761
6862
# make sure that all-masked data falls back to the viewlim
6762
6863
# set in convert.axisinfo....
0 commit comments