99
1010
1111def assert_position (cbar , expected ):
12-
1312 pos = cbar .ax .get_position ()
1413 result = [pos .x0 , pos .y0 , pos .width , pos .height ]
1514
1615 np .testing .assert_allclose (result , expected , atol = 1e-08 )
1716
1817
1918def assert_aspect (cbar , expected ):
20-
2119 assert cbar .ax .get_box_aspect () == expected
2220 # the aspect is given in pixel space (i.e. the size of the figure matters)
2321 np .testing .assert_allclose (cbar .ax .bbox .height / cbar .ax .bbox .width , expected )
2422
2523
2624def test_parse_shift_shrink ():
27-
2825 # test code for _parse_shift_shrink
2926 assert _parse_shift_shrink ("symmetric" , None ) == (0.0 , 0.0 )
3027
@@ -84,9 +81,7 @@ def test_parse_size_aspect_pad():
8481
8582@pytest .mark .parametrize ("orientation" , ["vertical" , "horizontal" ])
8683def test_colorbar_deprecate_positional (orientation ):
87-
8884 with subplots_context (1 , 2 ) as (f , axs ):
89-
9085 h = axs [0 ].pcolormesh ([[0 , 1 ]])
9186
9287 with pytest .warns (
@@ -96,7 +91,6 @@ def test_colorbar_deprecate_positional(orientation):
9691
9792
9893def test_colorbar_different_figures ():
99-
10094 with figure_context () as f1 , figure_context () as f2 :
10195 ax1 = f1 .subplots ()
10296 ax2 = f2 .subplots ()
@@ -108,7 +102,6 @@ def test_colorbar_different_figures():
108102
109103
110104def test_colorbar_ax_and_ax2_error ():
111-
112105 with figure_context () as f :
113106 ax1 , ax2 , ax3 = f .subplots (3 , 1 )
114107 h = ax1 .pcolormesh ([[0 , 1 ]])
@@ -118,7 +111,6 @@ def test_colorbar_ax_and_ax2_error():
118111
119112
120113def create_figure_subplots (nrows = 1 , ncols = 1 , orientation = "vertical" ):
121-
122114 f = plt .gcf ()
123115
124116 axs = f .subplots (nrows = nrows , ncols = ncols , squeeze = False )
@@ -143,23 +135,19 @@ def create_figure_subplots(nrows=1, ncols=1, orientation="vertical"):
143135
144136
145137def colorbar_one_ax_vertical (** kwargs ):
146-
147138 h , ax = create_figure_subplots ()
148139 cbar = mpu .colorbar (h , ax , ** kwargs )
149140 return cbar
150141
151142
152143def colorbar_one_ax_horizontal (** kwargs ):
153-
154144 h , ax = create_figure_subplots (orientation = "horizontal" )
155145 cbar = mpu .colorbar (h , ax , orientation = "horizontal" , ** kwargs )
156146 return cbar
157147
158148
159149def test_colorbar_vertical_aspect ():
160-
161150 with figure_context (figsize = (5 , 5 )):
162-
163151 # test pad=0, aspect=5
164152 cbar = colorbar_one_ax_vertical (aspect = 5 , pad = 0 )
165153
@@ -170,23 +158,20 @@ def test_colorbar_vertical_aspect():
170158 assert_aspect (cbar , 5 )
171159
172160 with figure_context (figsize = (4 , 2 )):
173-
174161 cbar = colorbar_one_ax_vertical (aspect = 20 , pad = 0 )
175162
176163 expected = [0.8 , 0.0 , 0.025 , 1 ]
177164 assert_position (cbar , expected )
178165 assert_aspect (cbar , 20 )
179166
180167 with figure_context (figsize = (2 , 4 )):
181-
182168 cbar = colorbar_one_ax_vertical (aspect = 20 , pad = 0 )
183169
184170 expected = [0.8 , 0.0 , 0.1 , 1 ]
185171 assert_position (cbar , expected )
186172 assert_aspect (cbar , 20 )
187173
188174 with figure_context (figsize = (5 , 5 )):
189-
190175 # test pad=0, aspect=default (=20)
191176 cbar = colorbar_one_ax_vertical (pad = 0 )
192177
@@ -196,9 +181,7 @@ def test_colorbar_vertical_aspect():
196181
197182
198183def test_colorbar_vertical_size ():
199-
200184 with figure_context () as f :
201-
202185 # test pad=0, size=0.2
203186 cbar = colorbar_one_ax_vertical (size = 0.2 , pad = 0 )
204187
@@ -213,7 +196,6 @@ def test_colorbar_vertical_size():
213196 assert_position (cbar , expected )
214197
215198 with figure_context ():
216-
217199 # pad=0.05, size=0.1
218200
219201 cbar = colorbar_one_ax_vertical (size = 0.1 , pad = 0.05 )
@@ -222,7 +204,6 @@ def test_colorbar_vertical_size():
222204 assert_position (cbar , expected )
223205
224206 with figure_context ():
225-
226207 # shift='symmetric', shrink=0.1
227208 # --> colorbar is 10 % smaller, and centered
228209
@@ -251,9 +232,7 @@ def test_colorbar_vertical_size():
251232
252233
253234def test_colorbar_horizontal_aspect ():
254-
255235 with figure_context (figsize = (5 , 5 )):
256-
257236 # test pad=0, aspect=5
258237 cbar = colorbar_one_ax_horizontal (aspect = 5 , pad = 0 )
259238
@@ -262,7 +241,6 @@ def test_colorbar_horizontal_aspect():
262241 assert_aspect (cbar , 1 / 5 )
263242
264243 with figure_context (figsize = (4 , 2 )):
265-
266244 # test pad=0, aspect=5
267245 cbar = colorbar_one_ax_horizontal (aspect = 20 , pad = 0 )
268246
@@ -271,7 +249,6 @@ def test_colorbar_horizontal_aspect():
271249 assert_aspect (cbar , 1 / 20 )
272250
273251 with figure_context (figsize = (2 , 4 )):
274-
275252 # test pad=0, aspect=5
276253 cbar = colorbar_one_ax_horizontal (aspect = 20 , pad = 0 )
277254
@@ -292,7 +269,6 @@ def test_colorbar_horizontal_aspect():
292269
293270
294271def test_colorbar_horizontal_size ():
295-
296272 with figure_context () as f :
297273 # test pad=0, size=0.2
298274 cbar = colorbar_one_ax_horizontal (size = 0.2 , pad = 0 )
@@ -344,7 +320,6 @@ def test_colorbar_horizontal_size():
344320
345321
346322def test_colorbar_vertical_two_axes ():
347-
348323 # use two horizontal axes
349324 with figure_context ():
350325 h , axs = create_figure_subplots (1 , 2 )
@@ -393,7 +368,6 @@ def test_colorbar_vertical_two_axes():
393368
394369
395370def test_colorbar_horizontal_two_axes ():
396-
397371 # use two horizontal axes
398372 with figure_context ():
399373 h , axs = create_figure_subplots (2 , 1 , orientation = "horizontal" )
@@ -457,9 +431,7 @@ def test_colorbar_horizontal_two_axes():
457431
458432
459433def test_colorbar_errors ():
460-
461434 with subplots_context () as (f , ax ):
462-
463435 h = ax .pcolormesh ([[0 , 1 ]])
464436
465437 with pytest .raises (
@@ -478,9 +450,7 @@ def test_colorbar_errors():
478450
479451
480452def test_get_cbax ():
481-
482453 with subplots_context () as (f , ax ):
483-
484454 cbax = _get_cbax (f )
485455
486456 assert isinstance (cbax , plt .Axes )
0 commit comments