@@ -1890,7 +1890,7 @@ def plot_group(group, ax):
1890
1890
1891
1891
def hist_frame (data , column = None , by = None , grid = True , xlabelsize = None ,
1892
1892
xrot = None , ylabelsize = None , yrot = None , ax = None , sharex = False ,
1893
- sharey = False , figsize = None , ** kwds ):
1893
+ sharey = False , figsize = None , layout = None , ** kwds ):
1894
1894
"""
1895
1895
Draw Histogram the DataFrame's series using matplotlib / pylab.
1896
1896
@@ -1916,6 +1916,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
1916
1916
sharey : bool, if True, the Y axis will be shared amongst all subplots.
1917
1917
figsize : tuple
1918
1918
The size of the figure to create in inches by default
1919
+ layout: (optional) a tuple (rows, columns) for the layout of the histograms
1919
1920
kwds : other plotting keyword arguments
1920
1921
To be passed to hist function
1921
1922
"""
@@ -1943,12 +1944,21 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
1943
1944
1944
1945
import matplotlib .pyplot as plt
1945
1946
n = len (data .columns )
1946
- rows , cols = 1 , 1
1947
- while rows * cols < n :
1948
- if cols > rows :
1949
- rows += 1
1950
- else :
1951
- cols += 1
1947
+
1948
+ if layout is not None :
1949
+ if not isinstance (layout , (tuple , list )) or len (layout ) != 2 :
1950
+ raise ValueError ('Layout must be a tuple of (rows, columns)' )
1951
+
1952
+ rows , cols = layout
1953
+ if rows * cols < n :
1954
+ raise ValueError ('Layout of %sx%s is incompatible with %s columns' % (rows , cols , n ))
1955
+ else :
1956
+ rows , cols = 1 , 1
1957
+ while rows * cols < n :
1958
+ if cols > rows :
1959
+ rows += 1
1960
+ else :
1961
+ cols += 1
1952
1962
fig , axes = _subplots (nrows = rows , ncols = cols , ax = ax , squeeze = False ,
1953
1963
sharex = sharex , sharey = sharey , figsize = figsize )
1954
1964
0 commit comments