@@ -51,3 +51,58 @@ def test_noticks():
5151 assert len (ax .get_yticks ()) == 0
5252
5353 plt .close (fig )
54+
55+ def test_get_bounds_spines ():
56+ fig , ax = plt .subplots ()
57+ ax .plot ([0 , 1 ], [0 , 1 ])
58+ ax .spines ["bottom" ].set_bounds (0 , 1 )
59+ ax .spines ["left" ].set_bounds (- 1 , 2 )
60+
61+ assert cu .get_bounds ("x" , ax = ax ) == (0 , 1 )
62+ assert cu .get_bounds ("y" , ax = ax ) == (- 1 , 2 )
63+ plt .close (fig )
64+
65+
66+ def test_get_bounds_label_fallback ():
67+ fig , ax = plt .subplots ()
68+ ax .plot ([0 , 1 , 2 , 3 ], [0 , 1 , 2 , 3 ])
69+ ax .set_xticks ([0 , 1 , 2 , 3 ])
70+ ax .set_xticklabels (["" , "a" , "" , "b" ])
71+
72+ assert cu .get_bounds ("x" , ax = ax ) == (1 , 3 )
73+ plt .close (fig )
74+
75+
76+ def test_breathe_adds_padding_and_hides_spines ():
77+ fig , ax = plt .subplots ()
78+ ax .plot ([0 , 1 ], [0 , 1 ])
79+ old_xlim = ax .get_xlim ()
80+ old_ylim = ax .get_ylim ()
81+
82+ cu .breathe (ax = ax )
83+
84+ new_xlim = ax .get_xlim ()
85+ new_ylim = ax .get_ylim ()
86+
87+ assert new_xlim [0 ] < old_xlim [0 ] and new_xlim [1 ] > old_xlim [1 ]
88+ assert new_ylim [0 ] < old_ylim [0 ] and new_ylim [1 ] > old_ylim [1 ]
89+
90+ assert not ax .spines ["top" ].get_visible ()
91+ assert not ax .spines ["right" ].get_visible ()
92+ assert ax .spines ["bottom" ].get_bounds () == old_xlim
93+ assert ax .spines ["left" ].get_bounds () == old_ylim
94+ plt .close (fig )
95+
96+
97+ def test_xclamp_yclamp ():
98+ fig , ax = plt .subplots ()
99+ ax .plot ([0 , 1 , 2 , 3 , 4 ], [0 , 1 , 2 , 3 , 4 ])
100+
101+ cu .xclamp (x0 = 0.5 , x1 = 3.4 , dt = 1.0 , ax = ax )
102+ assert ax .get_xlim () == (0.0 , 4.0 )
103+ assert list (ax .get_xticks ()) == [0.0 , 1.0 , 2.0 , 3.0 , 4.0 ]
104+
105+ cu .yclamp (y0 = 0.2 , y1 = 3.5 , dt = 1.0 , ax = ax )
106+ assert ax .get_ylim () == (0.0 , 4.0 )
107+ assert list (ax .get_yticks ()) == [0.0 , 1.0 , 2.0 , 3.0 , 4.0 ]
108+ plt .close (fig )
0 commit comments