Beispiel #1
0
def plot_stats_function(function,
                        statss,
                        paramss,
                        labels=None,
                        output_file=None,
                        limit=0):
    """
    function should take a L{pandas.DataFrame} and a dictionary and return a L{pandas.DataFrame}
    which will be plotted.
    statss and paramss are lists of L{pandas.DataFrame} and L{dict} respectively which will be passed to this function
    kwargss is a list of dictionaries, each of which will be passed to the plot function for the respective result of
    the function
    """
    styles = line_styles(len(statss))
    for i, (stats, params, style) in enumerate(zip(statss, paramss, styles)):
        if labels:
            label = labels[i]
        try:
            to_plot = function(stats, params)
            if limit:
                to_plot = to_plot[:limit]
            # to_plot.plot(style=style, label=label)
            ax = to_plot.plot(label=label, legend=False)
        except Exception as e:
            print e
    patches, labels = ax.get_legend_handles_labels()
    # plt.legend(loc='best').get_frame().set_alpha(0.6)
    if output_file:
        plt.savefig(output_file, bbox_inches='tight')
    plt.figure().legend(*ax.get_legend_handles_labels())
def plot_stats_function(function, statss, paramss, labels=None, output_file=None, limit=0):
    """
    function should take a L{pandas.DataFrame} and a dictionary and return a L{pandas.DataFrame}
    which will be plotted.
    statss and paramss are lists of L{pandas.DataFrame} and L{dict} respectively which will be passed to this function
    kwargss is a list of dictionaries, each of which will be passed to the plot function for the respective result of
    the function
    """
    styles = line_styles(len(statss))
    for i, (stats, params, style) in enumerate(zip(statss, paramss, styles)):
        if labels:
            label = labels[i]
        try:
            to_plot = function(stats, params)
            if limit:
                to_plot = to_plot[:limit]
            # to_plot.plot(style=style, label=label)
            ax = to_plot.plot(label=label, legend=False)
        except Exception as e:
            print e
    patches, labels = ax.get_legend_handles_labels()
    # plt.legend(loc='best').get_frame().set_alpha(0.6)
    if output_file:
        plt.savefig(output_file, bbox_inches='tight')
    plt.figure().legend(*ax.get_legend_handles_labels())
            return model_directory

    def paper_names(model_directory):
        for name, dir_ in DEFAULT_MODELS.items():
            if model_directory == dir_:
                return name

    relabel = paper_names

    stat_example = [s for s in all_stats.values() if len(s) != 0][0]
    import matplotlib.pyplot as plt
    for stat_name in stat_example:
        plt.figure()
        plt.title(stat_name)
        print len(all_stats)
        styles = line_styles(len(all_stats))
        for model_directory, style in zip(model_directories, styles):
            data = all_stats[model_directory]
            try:
                to_plot = data[stat_name]
                if args.limit:
                    to_plot = to_plot[to_plot.index <= args.limit]
                # ax = to_plot.plot(label=relabel(model_directory), style=style, legend=False, **stat_params[stat_name])
                ax = to_plot.plot(label=relabel(model_directory), legend=False, **stat_params[stat_name])
                plt.xlabel('training iterations')
                plt.ylabel(ys[stat_name])
                plt.subplots_adjust(bottom=0.15)
            except Exception as e:
                print 'exception'
                print stat_name, model_directory
                print e