plots.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:AlphaPy 作者: ScottFreeLLC 项目源码 文件源码
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
#
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号