@@ -472,6 +472,11 @@ def test_plot(self):
472
472
ax = _check_plot_works (self .ts .plot , subplots = True )
473
473
self ._check_axes_shape (ax , axes_num = 1 , layout = (1 , 1 ))
474
474
475
+ ax = _check_plot_works (self .ts .plot , subplots = True , layout = (- 1 , 1 ))
476
+ self ._check_axes_shape (ax , axes_num = 1 , layout = (1 , 1 ))
477
+ ax = _check_plot_works (self .ts .plot , subplots = True , layout = (1 , - 1 ))
478
+ self ._check_axes_shape (ax , axes_num = 1 , layout = (1 , 1 ))
479
+
475
480
@slow
476
481
def test_plot_figsize_and_title (self ):
477
482
# figsize and title
@@ -677,9 +682,21 @@ def test_hist_layout_with_by(self):
677
682
axes = _check_plot_works (df .height .hist , by = df .gender , layout = (2 , 1 ))
678
683
self ._check_axes_shape (axes , axes_num = 2 , layout = (2 , 1 ))
679
684
685
+ axes = _check_plot_works (df .height .hist , by = df .gender , layout = (3 , - 1 ))
686
+ self ._check_axes_shape (axes , axes_num = 2 , layout = (3 , 1 ))
687
+
680
688
axes = _check_plot_works (df .height .hist , by = df .category , layout = (4 , 1 ))
681
689
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
682
690
691
+ axes = _check_plot_works (df .height .hist , by = df .category , layout = (2 , - 1 ))
692
+ self ._check_axes_shape (axes , axes_num = 4 , layout = (2 , 2 ))
693
+
694
+ axes = _check_plot_works (df .height .hist , by = df .category , layout = (3 , - 1 ))
695
+ self ._check_axes_shape (axes , axes_num = 4 , layout = (3 , 2 ))
696
+
697
+ axes = _check_plot_works (df .height .hist , by = df .category , layout = (- 1 , 4 ))
698
+ self ._check_axes_shape (axes , axes_num = 4 , layout = (1 , 4 ))
699
+
683
700
axes = _check_plot_works (df .height .hist , by = df .classroom , layout = (2 , 2 ))
684
701
self ._check_axes_shape (axes , axes_num = 3 , layout = (2 , 2 ))
685
702
@@ -927,7 +944,11 @@ def test_plot(self):
927
944
_check_plot_works (df .plot , grid = False )
928
945
axes = _check_plot_works (df .plot , subplots = True )
929
946
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
930
- _check_plot_works (df .plot , subplots = True , use_index = False )
947
+
948
+ axes = _check_plot_works (df .plot , subplots = True , layout = (- 1 , 2 ))
949
+ self ._check_axes_shape (axes , axes_num = 4 , layout = (2 , 2 ))
950
+
951
+ axes = _check_plot_works (df .plot , subplots = True , use_index = False )
931
952
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
932
953
933
954
df = DataFrame ({'x' : [1 , 2 ], 'y' : [3 , 4 ]})
@@ -985,6 +1006,9 @@ def test_plot(self):
985
1006
axes = _check_plot_works (df .plot , kind = 'bar' , subplots = True )
986
1007
self ._check_axes_shape (axes , axes_num = 1 , layout = (1 , 1 ))
987
1008
1009
+ axes = _check_plot_works (df .plot , kind = 'bar' , subplots = True ,
1010
+ layout = (- 1 , 1 ))
1011
+ self ._check_axes_shape (axes , axes_num = 1 , layout = (1 , 1 ))
988
1012
# When ax is supplied and required number of axes is 1,
989
1013
# passed ax should be used:
990
1014
fig , ax = self .plt .subplots ()
@@ -1174,12 +1198,30 @@ def test_subplots_layout(self):
1174
1198
self ._check_axes_shape (axes , axes_num = 3 , layout = (2 , 2 ))
1175
1199
self .assertEqual (axes .shape , (2 , 2 ))
1176
1200
1201
+ axes = df .plot (subplots = True , layout = (- 1 , 2 ))
1202
+ self ._check_axes_shape (axes , axes_num = 3 , layout = (2 , 2 ))
1203
+ self .assertEqual (axes .shape , (2 , 2 ))
1204
+
1205
+ axes = df .plot (subplots = True , layout = (2 , - 1 ))
1206
+ self ._check_axes_shape (axes , axes_num = 3 , layout = (2 , 2 ))
1207
+ self .assertEqual (axes .shape , (2 , 2 ))
1208
+
1177
1209
axes = df .plot (subplots = True , layout = (1 , 4 ))
1178
1210
self ._check_axes_shape (axes , axes_num = 3 , layout = (1 , 4 ))
1179
1211
self .assertEqual (axes .shape , (1 , 4 ))
1180
1212
1213
+ axes = df .plot (subplots = True , layout = (- 1 , 4 ))
1214
+ self ._check_axes_shape (axes , axes_num = 3 , layout = (1 , 4 ))
1215
+ self .assertEqual (axes .shape , (1 , 4 ))
1216
+
1217
+ axes = df .plot (subplots = True , layout = (4 , - 1 ))
1218
+ self ._check_axes_shape (axes , axes_num = 3 , layout = (4 , 1 ))
1219
+ self .assertEqual (axes .shape , (4 , 1 ))
1220
+
1181
1221
with tm .assertRaises (ValueError ):
1182
1222
axes = df .plot (subplots = True , layout = (1 , 1 ))
1223
+ with tm .assertRaises (ValueError ):
1224
+ axes = df .plot (subplots = True , layout = (- 1 , - 1 ))
1183
1225
1184
1226
# single column
1185
1227
df = DataFrame (np .random .rand (10 , 1 ),
@@ -1228,6 +1270,14 @@ def test_subplots_multiple_axes(self):
1228
1270
self ._check_axes_shape (returned , axes_num = 4 , layout = (2 , 2 ))
1229
1271
self .assertEqual (returned .shape , (4 , ))
1230
1272
1273
+ returned = df .plot (subplots = True , ax = axes , layout = (2 , - 1 ))
1274
+ self ._check_axes_shape (returned , axes_num = 4 , layout = (2 , 2 ))
1275
+ self .assertEqual (returned .shape , (4 , ))
1276
+
1277
+ returned = df .plot (subplots = True , ax = axes , layout = (- 1 , 2 ))
1278
+ self ._check_axes_shape (returned , axes_num = 4 , layout = (2 , 2 ))
1279
+ self .assertEqual (returned .shape , (4 , ))
1280
+
1231
1281
# single column
1232
1282
fig , axes = self .plt .subplots (1 , 1 )
1233
1283
df = DataFrame (np .random .rand (10 , 1 ),
@@ -2135,6 +2185,10 @@ def test_hist_layout(self):
2135
2185
{'layout' : (4 , 1 ), 'expected_size' : (4 , 1 )},
2136
2186
{'layout' : (1 , 4 ), 'expected_size' : (1 , 4 )},
2137
2187
{'layout' : (3 , 3 ), 'expected_size' : (3 , 3 )},
2188
+ {'layout' : (- 1 , 4 ), 'expected_size' : (1 , 4 )},
2189
+ {'layout' : (4 , - 1 ), 'expected_size' : (4 , 1 )},
2190
+ {'layout' : (- 1 , 2 ), 'expected_size' : (2 , 2 )},
2191
+ {'layout' : (2 , - 1 ), 'expected_size' : (2 , 2 )}
2138
2192
)
2139
2193
2140
2194
for layout_test in layout_to_expected_size :
@@ -2149,6 +2203,9 @@ def test_hist_layout(self):
2149
2203
# invalid format for layout
2150
2204
with tm .assertRaises (ValueError ):
2151
2205
df .hist (layout = (1 ,))
2206
+ with tm .assertRaises (ValueError ):
2207
+ df .hist (layout = (- 1 , - 1 ))
2208
+
2152
2209
2153
2210
@slow
2154
2211
def test_scatter (self ):
@@ -3048,6 +3105,8 @@ def test_grouped_box_layout(self):
3048
3105
by = df .gender , layout = (1 , 1 ))
3049
3106
self .assertRaises (ValueError , df .boxplot , column = ['height' , 'weight' , 'category' ],
3050
3107
layout = (2 , 1 ), return_type = 'dict' )
3108
+ self .assertRaises (ValueError , df .boxplot , column = ['weight' , 'height' ],
3109
+ by = df .gender , layout = (- 1 , - 1 ))
3051
3110
3052
3111
box = _check_plot_works (df .groupby ('gender' ).boxplot , column = 'height' ,
3053
3112
return_type = 'dict' )
@@ -3080,15 +3139,29 @@ def test_grouped_box_layout(self):
3080
3139
box = _check_plot_works (df .groupby ('category' ).boxplot , column = 'height' ,
3081
3140
layout = (3 , 2 ), return_type = 'dict' )
3082
3141
self ._check_axes_shape (self .plt .gcf ().axes , axes_num = 4 , layout = (3 , 2 ))
3142
+ box = _check_plot_works (df .groupby ('category' ).boxplot , column = 'height' ,
3143
+ layout = (3 , - 1 ), return_type = 'dict' )
3144
+ self ._check_axes_shape (self .plt .gcf ().axes , axes_num = 4 , layout = (3 , 2 ))
3083
3145
3084
- box = df .boxplot (column = ['height' , 'weight' , 'category' ], by = 'gender' , layout = (4 , 1 ))
3146
+ box = df .boxplot (column = ['height' , 'weight' , 'category' ], by = 'gender' ,
3147
+ layout = (4 , 1 ))
3085
3148
self ._check_axes_shape (self .plt .gcf ().axes , axes_num = 3 , layout = (4 , 1 ))
3086
3149
3150
+ box = df .boxplot (column = ['height' , 'weight' , 'category' ], by = 'gender' ,
3151
+ layout = (- 1 , 1 ))
3152
+ self ._check_axes_shape (self .plt .gcf ().axes , axes_num = 3 , layout = (3 , 1 ))
3153
+
3087
3154
box = df .groupby ('classroom' ).boxplot (
3088
3155
column = ['height' , 'weight' , 'category' ], layout = (1 , 4 ),
3089
3156
return_type = 'dict' )
3090
3157
self ._check_axes_shape (self .plt .gcf ().axes , axes_num = 3 , layout = (1 , 4 ))
3091
3158
3159
+ box = df .groupby ('classroom' ).boxplot (
3160
+ column = ['height' , 'weight' , 'category' ], layout = (1 , - 1 ),
3161
+ return_type = 'dict' )
3162
+ self ._check_axes_shape (self .plt .gcf ().axes , axes_num = 3 , layout = (1 , 3 ))
3163
+
3164
+
3092
3165
@slow
3093
3166
def test_grouped_box_multiple_axes (self ):
3094
3167
# GH 6970, GH 7069
@@ -3132,13 +3205,23 @@ def test_grouped_hist_layout(self):
3132
3205
layout = (1 , 1 ))
3133
3206
self .assertRaises (ValueError , df .hist , column = 'height' , by = df .category ,
3134
3207
layout = (1 , 3 ))
3208
+ self .assertRaises (ValueError , df .hist , column = 'height' , by = df .category ,
3209
+ layout = (- 1 , - 1 ))
3210
+
3211
+ axes = _check_plot_works (df .hist , column = 'height' , by = df .gender ,
3212
+ layout = (2 , 1 ))
3213
+ self ._check_axes_shape (axes , axes_num = 2 , layout = (2 , 1 ))
3135
3214
3136
- axes = _check_plot_works (df .hist , column = 'height' , by = df .gender , layout = (2 , 1 ))
3215
+ axes = _check_plot_works (df .hist , column = 'height' , by = df .gender ,
3216
+ layout = (2 , - 1 ))
3137
3217
self ._check_axes_shape (axes , axes_num = 2 , layout = (2 , 1 ))
3138
3218
3139
3219
axes = df .hist (column = 'height' , by = df .category , layout = (4 , 1 ))
3140
3220
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
3141
3221
3222
+ axes = df .hist (column = 'height' , by = df .category , layout = (- 1 , 1 ))
3223
+ self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 1 ))
3224
+
3142
3225
axes = df .hist (column = 'height' , by = df .category , layout = (4 , 2 ), figsize = (12 , 8 ))
3143
3226
self ._check_axes_shape (axes , axes_num = 4 , layout = (4 , 2 ), figsize = (12 , 8 ))
3144
3227
tm .close ()
0 commit comments