def score_hist(df, columns=None, groupby=None, threshold=0.7, stacked=True,
               bins=20, percent=True, alpha=0.33, show=True, block=False, save=False):
    """Plot multiple histograms on one plot, typically of "score" values between 0 and 1
    Typically the groupby or columns of the dataframe are the classification categories (0, .5, 1)
    And the values are scores between 0 and 1.
    """
    df = df if columns is None else df[([] if groupby is None else [groupby]) + list(columns)].copy()
    if groupby is not None or threshold is not None:
        df = groups_from_scores(df, groupby=groupby, threshold=threshold)
    percent = 100. if percent else 1.
    if isinstance(df, pd.core.groupby.DataFrameGroupBy):
        df = df_from_groups(df, columns=columns) * percent
    columns = df.columns if columns is None else columns
    if bins is None:
        bins = 20
    if isinstance(bins, int):
        bins = np.linspace(np.min(df.min()), np.max(df.max()), bins)
    log.debug('bins: {}'.format(bins))
    figs = []

    df.plot(kind='hist', alpha=alpha, stacked=stacked, bins=bins)
    # for col in df.columns:
    #     series = df[col] * percent
    #     log.debug('{}'.format(series))
    #     figs.append(plt.hist(series, bins=bins, alpha=alpha,
    #                 weights=percent * np.ones_like(series) / len(series.dropna()),
    #                 label=stringify(col)))
    plt.legend()
    plt.xlabel('Score (%)')
    plt.ylabel('Percent')
    plt.title('{} Scores for {}'.format(np.sum(df.count()), columns))
    plt.draw()
    if save or not show:
        fig = plt.gcf()
        today = datetime.datetime.today()
        fig.savefig(os.path.join(IMAGES_PATH, 'score_hist_{:04d}-{:02d}-{:02d}_{:02d}{:02d}.jpg'.format(*today.timetuple())))
    if show:
        plt.show(block=block)
    return figs
def score_hist ( df , columns = None , groupby = None , threshold = 0.7 , stacked = True , bins = 20 , percent = True , alpha = 0.33 , show = True , block = False , save = False ) : df = df if columns is None else df [ ( [ ] if groupby is None else [ groupby ] ) + list ( columns ) ] . copy ( ) if groupby is not None or threshold is not None : df = groups_from_scores ( df , groupby = groupby , threshold = threshold ) percent = 100. if percent else 1. if isinstance ( df , pd . core . groupby . DataFrameGroupBy ) : df = df_from_groups ( df , columns = columns ) * percent columns = df . columns if columns is None else columns if bins is None : bins = 20 if isinstance ( bins , int ) : bins = np . linspace ( np . min ( df . min ( ) ) , np . max ( df . max ( ) ) , bins ) log . debug ( 'bins: {}' . format ( bins ) ) figs = [ ] df . plot ( kind = 'hist' , alpha = alpha , stacked = stacked , bins = bins ) plt . legend ( ) plt . xlabel ( 'Score (%)' ) plt . ylabel ( 'Percent' ) plt . title ( '{} Scores for {}' . format ( np . sum ( df . count ( ) ) , columns ) ) plt . draw ( ) if save or not show : fig = plt . gcf ( ) today = datetime . datetime . today ( ) fig . savefig ( os . path . join ( IMAGES_PATH , 'score_hist_{:04d}-{:02d}-{:02d}_{:02d}{:02d}.jpg' . format ( * today . timetuple ( ) ) ) ) if show : plt . show ( block = block ) return figs
Plot multiple histograms on one plot, typically of "score" values between 0 and 1
    Typically the groupby or columns of the dataframe are the classification categories (0, .5, 1)
    And the values are scores between 0 and 1.