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