66from . import subplots_context
77
88
9- def test_default_width ():
9+ def test_set_map_layout_default_width ():
1010
1111 with subplots_context () as (f , ax ):
1212 set_map_layout (ax )
@@ -17,7 +17,7 @@ def test_default_width():
1717@pytest .mark .parametrize (
1818 "nrow_ncol" , [{"nrow" : None , "ncol" : None }, {"nrow" : 1 , "ncol" : 1 }]
1919)
20- def test_no_borders (nrow_ncol ):
20+ def test_set_map_layout_no_borders (nrow_ncol ):
2121
2222 # width:height = 1:1
2323 with subplots_context () as (f , ax ):
@@ -50,7 +50,21 @@ def test_no_borders(nrow_ncol):
5050 assert np .allclose ((width , height ), (10 , 20 ))
5151
5252
53- def test_vert_borders ():
53+ @pytest .mark .parametrize ("ax_to_arr" , (lambda ax : [ax ], lambda ax : np .array (ax )))
54+ def test_set_map_layout_ax_arr (ax_to_arr ):
55+
56+ # width:height = 1:1
57+ with subplots_context () as (f , ax ):
58+ ax .set_aspect ("equal" )
59+ ax .set (xlim = (0 , 1 ), ylim = (0 , 1 ))
60+ f .subplots_adjust (left = 0 , bottom = 0 , right = 1 , top = 1 )
61+ set_map_layout (ax_to_arr (ax ), 10 )
62+
63+ width , height = f .get_size_inches () * 2.54
64+ assert np .allclose ((width , height ), (10 , 10 ))
65+
66+
67+ def test_set_map_layout_vert_borders ():
5468
5569 # width:height = 1:1
5670 with subplots_context () as (f , ax ):
@@ -89,7 +103,7 @@ def test_vert_borders():
89103 assert np .allclose ((width , height ), (10 , 40 ))
90104
91105
92- def test_horz_borders ():
106+ def test_set_map_layout_horz_borders ():
93107
94108 # width:height = 1:1
95109 with subplots_context () as (f , ax ):
@@ -116,7 +130,65 @@ def test_horz_borders():
116130 assert np .allclose ((width , height ), (10 , 5 ))
117131
118132
119- def test_nrow_ncol_only_one_raises ():
133+ def test_set_map_layout_two_axes_vert ():
134+
135+ # width:height = 1:1
136+ with subplots_context (2 , 1 ) as (f , axs ):
137+ for ax in axs :
138+ ax .set_aspect ("equal" )
139+ ax .set (xlim = (0 , 1 ), ylim = (0 , 1 ))
140+
141+ f .subplots_adjust (left = 0 , bottom = 0 , right = 1 , top = 1 , hspace = 0 )
142+
143+ set_map_layout (ax , 10 )
144+
145+ width , height = f .get_size_inches () * 2.54
146+ assert np .allclose ((width , height ), (10 , 20 ))
147+
148+ # width:height = 1:1
149+ with subplots_context (2 , 1 ) as (f , axs ):
150+ for ax in axs :
151+ ax .set_aspect ("equal" )
152+ ax .set (xlim = (0 , 1 ), ylim = (0 , 1 ))
153+
154+ f .subplots_adjust (left = 0 , bottom = 0 , right = 1 , top = 1 , hspace = 1 )
155+
156+ set_map_layout (ax , 10 )
157+
158+ width , height = f .get_size_inches () * 2.54
159+ assert np .allclose ((width , height ), (10 , 30 ))
160+
161+
162+ def test_set_map_layout_two_axes_horz ():
163+
164+ # width:height = 1:1
165+ with subplots_context (1 , 2 ) as (f , axs ):
166+ for ax in axs :
167+ ax .set_aspect ("equal" )
168+ ax .set (xlim = (0 , 1 ), ylim = (0 , 1 ))
169+
170+ f .subplots_adjust (left = 0 , bottom = 0 , right = 1 , top = 1 , wspace = 0 )
171+
172+ set_map_layout (ax , 10 )
173+
174+ width , height = f .get_size_inches () * 2.54
175+ assert np .allclose ((width , height ), (10 , 5 ))
176+
177+ # width:height = 1:1
178+ with subplots_context (1 , 2 ) as (f , axs ):
179+ for ax in axs :
180+ ax .set_aspect ("equal" )
181+ ax .set (xlim = (0 , 1 ), ylim = (0 , 1 ))
182+
183+ f .subplots_adjust (left = 0 , bottom = 0 , right = 1 , top = 1 , wspace = 1 )
184+
185+ set_map_layout (ax , 10 )
186+
187+ width , height = f .get_size_inches () * 2.54
188+ assert np .allclose ((width , height ), (10 , 10 / 3 ))
189+
190+
191+ def test_set_map_layout_nrow_ncol_only_one_raises ():
120192
121193 with pytest .raises (ValueError , match = "Must set none or both of 'nrow' and 'ncol'" ):
122194 set_map_layout (None , width = 17.0 , nrow = 1 , ncol = None )
0 commit comments