MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / plot_facet_grid

Function plot_facet_grid

alphapy/plots.py:982–1032  ·  view source on GitHub ↗

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

(df, target, frow, fcol, tag='eda', directory=None)

Source from the content-addressed store, hash-verified

980#
981
982def plot_facet_grid(df, target, frow, fcol, tag='eda', directory=None):
983 r"""Plot a Seaborn faceted histogram grid.
984
985 Parameters
986 ----------
987 df : pandas.DataFrame
988 The dataframe containing the features.
989 target : str
990 The target variable for contrast.
991 frow : list of str
992 Feature names for the row elements of the grid.
993 fcol : list of str
994 Feature names for the column elements of the grid.
995 tag : str
996 Unique identifier for the plot.
997 directory : str, optional
998 The full specification of the plot location.
999
1000 Returns
1001 -------
1002 None : None.
1003
1004 References
1005 ----------
1006
1007 http://seaborn.pydata.org/generated/seaborn.FacetGrid.html
1008
1009 """
1010
1011 logger.info("Generating Facet Grid")
1012
1013 # Calculate the number of bins using the Freedman-Diaconis rule.
1014
1015 tlen = len(df[target])
1016 tmax = df[target].max()
1017 tmin = df[target].min()
1018 trange = tmax - tmin
1019 iqr = df[target].quantile(Q3) - df[target].quantile(Q1)
1020 h = 2 * iqr * (tlen ** (-1/3))
1021 nbins = math.ceil(trange / h)
1022
1023 # Generate the pair plot
1024
1025 sns.set(style="darkgrid")
1026
1027 fg = sns.FacetGrid(df, row=frow, col=fcol, margin_titles=True)
1028 bins = np.linspace(tmin, tmax, nbins)
1029 fg.map(plt.hist, target, color="steelblue", bins=bins, lw=0)
1030
1031 # Save the plot
1032 write_plot('seaborn', fg, 'facet_grid', tag, directory)
1033
1034
1035#

Callers

nothing calls this directly

Calls 1

write_plotFunction · 0.85

Tested by

no test coverage detected