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