def make_pretty_generation_plot(filename, generations, lines_to_plot, x_axis_name, legend_labels, y_errorbar=None, y_logscale = False, vline_x = [], save_figure = True): if y_errorbar: assert isinstance(y_errorbar, list), "Please provide a list for error bars" assert len(y_errorbar) == len(lines_to_plot), "When plotting error bars you must specify an array of error bars for each line that is plotted" cmap = brewer2mpl.get_map('Set1', 'qualitative', 9) p = Ppl(cmap, alpha=1) fig, ax = plt.subplots(1) ax.set_xlabel('Generation') ax.set_ylabel(x_axis_name) if y_logscale: ax.set_yscale('log') plt.grid(b=True, which='both', axis='y', color='0.65',linestyle='dashed') legend_labels = map(lambda s: s + ' (log)', legend_labels) else: ax.yaxis.get_major_formatter().set_powerlimits((0, 1)) for i, (series, label) in enumerate(zip(lines_to_plot, legend_labels)): p.plot(ax, generations, series, linewidth=2, label=label, zorder=2) if y_errorbar: for i, (series, label) in enumerate(zip(lines_to_plot, legend_labels)): ax.errorbar(generations, series, yerr=y_errorbar[i], zorder=1, capsize=2, barsabove=True, ecolor = errorbar_color) if vline_x: for x in vline_x: ax.vlines(x = x, ymin = ax.get_ylim()[0], ymax = ax.get_ylim()[1], linewidth = 1, linestyles = 'dashed', alpha = 0.5) p.legend(ax, loc=0) if save_figure: fig.savefig(filename) return fig, ax, filename
def get_pretty_xy_plot(x, y, xlabel, ylabel, filename, y_errorbar=None, save_figure = True): cmap = brewer2mpl.get_map('Set1', 'qualitative', 9) p = Ppl(cmap, alpha=1) fig, ax = plt.subplots(1) ax.set_xlabel(pfn(xlabel)) ax.set_ylabel(pfn(ylabel)) ax.yaxis.get_major_formatter().set_powerlimits((0, 1)) print "Errorbar: %s"%y_errorbar if y_errorbar is not None: ax.errorbar(x, y, yerr=y_errorbar, fmt='o') p.plot(ax, x, y, linewidth=2,) if save_figure: fig.savefig(filename) return ax, fig
def multiline_xy_plot(x, ys, xlabel, ylabel, legend_labels, filename, y_errorbars=None, save_figure = True): assert isinstance(ys, list) cmap = brewer2mpl.get_map('Set1', 'qualitative', 9) p = Ppl(cmap, alpha=1) fig, ax = plt.subplots(1) ax.set_xlabel(fl(xlabel)) ax.set_ylabel(fl(ylabel)) ax.yaxis.get_major_formatter().set_powerlimits((0, 1)) for i, y in enumerate(ys): #print "Errorbar: %s"%y_errorbar #if y_errorbars is not None: ax.errorbar(x, y, yerr=y_errorbar, fmt='o') #print legend_labels[i] p.plot(ax, x, y, linewidth=2, label = legend_labels[i]) p.legend(ax, loc=0, frameon = False) if save_figure: fig.savefig(filename) return ax, fig
def make_pretty_tradeprice_plot(rounds, prices, filename, format = 'png', **figargs): from settings import default_parameters as dp cmap = brewer2mpl.get_map('Set1', 'qualitative', 9) p = Ppl(cmap, alpha=1) fig = plt.figure(num=None, **figargs) ax = fig.add_subplot(1,1,1) #fig, ax = plt.subplots(1) """ if kwargs.has_key('dpi'): fig.set_dpi(kwargs['dpi']) if kwargs.has_key('figwidth'): fig.set_figwidth(kwargs['figwidth']) if kwargs.has_key('figheight'): fig.set_figheight(kwargs['figheight']) """ p.plot(ax, rounds, prices, zorder=1) #ax.yaxis.get_major_formatter().set_powerlimits((0, 1)) ### Plotting statbility margins fas = get_fundamental_after_shock() ax.hlines(y = [fas - settings.stability_margin, fas + settings.stability_margin], xmin=0, xmax=settings.n_simulation_rounds, linestyles = 'dashed') ### Plotting fundamental step function y = [dp['fundamental_initial_value'], dp['fundamental_initial_value'] + dp['fundamental_shock_size'], ] xmin = [0, dp['fundamental_shock_round']] xmax = [dp['fundamental_shock_round'], settings.n_simulation_rounds] ax.hlines(y, xmin, xmax, linestyles = 'solid', colors='black', linewidth=2, zorder=2) ax.vlines(x = dp['fundamental_shock_round'], ymin=dp['fundamental_initial_value'] + dp['fundamental_shock_size'], ymax = dp['fundamental_initial_value'], colors='black', linewidth=2, zorder=3) ax.set_ylabel('Traded price (ticks)') ax.set_xlabel('Time (rounds)') ax.set_xlim([0, max(rounds)]) ax.set_ylim([min(fas - settings.stability_margin-2, min(prices)), max(fas + settings.stability_margin, max(prices))]) fig.savefig(filename) plt.close() gc.collect()