def plot_facet_grid(df, target, frow, fcol, tag='eda', directory=None):
r"""Plot a Seaborn faceted histogram grid.
Parameters
----------
df : pandas.DataFrame
The dataframe containing the features.
target : str
The target variable for contrast.
frow : list of str
Feature names for the row elements of the grid.
fcol : list of str
Feature names for the column elements of the grid.
tag : str
Unique identifier for the plot.
directory : str, optional
The full specification of the plot location.
Returns
-------
None : None.
References
----------
http://seaborn.pydata.org/generated/seaborn.FacetGrid.html
"""
logger.info("Generating Facet Grid")
# Calculate the number of bins using the Freedman-Diaconis rule.
tlen = len(df[target])
tmax = df[target].max()
tmin = df[target].min()
trange = tmax - tmin
iqr = df[target].quantile(Q3) - df[target].quantile(Q1)
h = 2 * iqr * (tlen ** (-1/3))
nbins = math.ceil(trange / h)
# Generate the pair plot
sns.set(style="darkgrid")
fg = sns.FacetGrid(df, row=frow, col=fcol, margin_titles=True)
bins = np.linspace(tmin, tmax, nbins)
fg.map(plt.hist, target, color="steelblue", bins=bins, lw=0)
# Save the plot
write_plot('seaborn', fg, 'facet_grid', tag, directory)
#
# Function plot_distribution
#
评论列表
文章目录