def line_plot(result_file, dest, order=None, inset_result_file=None, inset_title=None, title=None, legend_pos=None, legend_cols=None, xlabel=None, ylabel=None): headers, labels, ys = read_results_file(result_file) cats = headers[1:] x = sorted([int(num_clicks) for num_clicks in labels]) # reorder the data that will be plotted and set legend labels legend_labels = [] if order is not None: new_ys = [] for catid, catname in order: new_ys.append(ys[cats.index(catid)]) legend_labels.append(catname) ys = new_ys else: legend_labels = cats[:] fig = plt.figure() ax = fig.add_subplot(111) colors = ['#fdb863', '#e66101', '#b2abd2', '#5e3c99'] markers = ['s', 'o', '^', 'x'] curves = [] for i in range(len(ys)): curve = ax.plot(x, ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] #curve = ax.errorbar(x, ys[i], errors[i], color=colors[i]) curves.append(curve) # display a subfigure id if this is going to be part of a subfigure plt.figtext(0.025, 0.025, "b", fontsize=30, weight='bold') legend_str = legend_pos if legend_pos is not None else "upper right" cols = legend_cols if legend_cols is not None else 2 ax.legend(curves, legend_labels, loc=legend_str, shadow=False, ncol=cols, prop=FontProperties(size=18), numpoints=1) plt.xlim(x[0] - .2 * x[0], x[-1] + .9 * x[-1]) #plt.ylim(ys[0][0] - .2 * ys[0][0], ys[0][-1] + .05 * ys[0][-1]) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(22) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(22) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=22) if ylabel is not None: ax.set_ylabel(ylabel, fontsize=22) if title is not None: plt.title(title, fontsize=22) ax.set_xscale('log') plt.grid(True, color="#bbbbbb") # add an inset to the figure if inset_result_file is not None: inset_ax = plt.axes([.6, .2, .35, .26]) inset_headers, inset_labels, inset_ys = read_results_file(inset_result_file) inset_x = sorted([int(num_clicks) for num_clicks in inset_labels]) # reorder the data that will be plotted and set legend labels if order is not None: new_inset_ys = [] for catid, catname in order: new_inset_ys.append(inset_ys[cats.index(catid)]) inset_ys = new_inset_ys inset_curves = [] for i in range(len(inset_ys)): curve = inset_ax.plot(inset_x, inset_ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] inset_curves.append(curve) inset_ax.set_xscale('log') if inset_title is not None: inset_ax.set_title(inset_title) pp = PdfPages(dest) fig.savefig(pp, format='pdf') pp.close() plt.close()
def line_plot(result_file, dest, order=None, inset_result_file=None, inset_title=None, title=None, legend_pos=None, legend_cols=None, xlabel=None, ylabel=None): headers, labels, ys = read_results_file(result_file) cats = headers[1:] x = range(len(labels)) # reorder the data that will be plotted and set legend labels legend_labels = [] if order is not None: new_ys = [] for catid, catname in order: new_ys.append(ys[cats.index(catid)]) legend_labels.append(catname) ys = new_ys else: legend_labels = cats[:] # make the y axis in millions reduce_y = lambda y: [yi / 1000000.0 for yi in y] ys = [reduce_y(y) for y in ys] fig = plt.figure() ax = fig.add_subplot(111) curves = plot_areas(x, ys, ax) # display a subfigure id if this is going to be part of a subfigure plt.figtext(0.025, 0.025, "a", fontsize=30, weight='bold') # display the legends legend_str = legend_pos if legend_pos is not None else "upper right" cols = legend_cols if legend_cols is not None else 2 ax.legend(curves, legend_labels, shadow=False, ncol=cols, prop=FontProperties(size=12), numpoints=1, bbox_to_anchor=(.32, .99)) # x-axis labels: # a. pritify # b. display every other label nice_labels = create_nice_labels(labels) xreduced = [] labels_reduced = [] count = 0 for i in range(len(x)): count += 1 if count % 2 == 0: xreduced.append(x[i]) labels_reduced.append(nice_labels[i]) plt.xticks(xreduced, labels_reduced, rotation=60) plt.xlim(x[0], x[-1]) # set font sizes for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(16) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(22) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=22) if ylabel is not None: ax.set_ylabel(ylabel, fontsize=22) if title is not None: plt.title(title, fontsize=22) plt.grid(True, color="#bbbbbb") if inset_result_file is not None: inset_ax = plt.axes([.56, .69, .39, .2]) inset_headers, inset_labels, inset_ys = read_results_file(inset_result_file) inset_ys = [reduce_y(y) for y in inset_ys] if order is not None: new_inset_ys = [] for catid, catname in order: new_inset_ys.append(inset_ys[cats.index(catid)]) inset_ys = new_inset_ys inset_curves = plot_areas(range(len(inset_ys[0])), inset_ys, inset_ax) inset_ax.axes.get_xaxis().set_visible(False) if inset_title is not None: inset_ax.set_title(inset_title) pp = PdfPages(dest) fig.savefig(pp, format='pdf') pp.close() plt.close()
def pbox_plot(results_file, dest, order=None, inset_results_file=None, inset_title=None, title=None, xlabel=None, ylabel=None): headers, labels, ys = read_results_file(results_file) cats = headers[1:] x = range(len(labels)) # reorder the data that will be plotted and set legend labels xlabels = [] if order is not None: new_ys = [] for catid, catname in order: new_ys.append(ys[cats.index(catid)]) xlabels.append(catname) ys = new_ys else: xlabels = cats[:] fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.yaxis.grid(color="#bbbbbb") draw_boxes(ys, ax) plt.xticks(range(1, len(xlabels) + 1), xlabels) ax.yaxis.set_major_locator(MaxNLocator(nbins=7)) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(22) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(22) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=22) if ylabel is not None: ax.set_ylabel(ylabel, fontsize=22) if title is not None: plt.title(title, fontsize=22) # plot the inset if inset_results_file is not None: inset_ax = plt.axes([.66, .10, .3, .34]) inset_headers, inset_labels, inset_ys = read_results_file(inset_results_file) if order is not None: new_inset_ys = [] for catid, catname in order: new_inset_ys.append(inset_ys[cats.index(catid)]) inset_ys = new_inset_ys draw_boxes(inset_ys, inset_ax) inset_ax.axes.get_xaxis().set_visible(False) if inset_title is not None: inset_ax.set_title(inset_title) pp = PdfPages(dest) fig.savefig(pp, format='pdf') pp.close() plt.close()
def pbox_plot(results_file, dest, order=None, inset_results_file=None, inset_title=None, title=None, xlabel=None, ylabel=None): headers, labels, ys = read_results_file(results_file) cats = headers[1:] x = range(len(labels)) # reorder the data that will be plotted and set legend labels xlabels = [] if order is not None: new_ys = [] for catid, catname in order: new_ys.append(ys[cats.index(catid)]) xlabels.append(catname) ys = new_ys else: xlabels = cats[:] fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.yaxis.grid(color="#bbbbbb") draw_boxes(ys, ax) plt.xticks(range(1, len(xlabels) + 1), xlabels) ax.yaxis.set_major_locator(MaxNLocator(nbins=7)) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(22) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(22) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=22) if ylabel is not None: ax.set_ylabel(ylabel, fontsize=22) if title is not None: plt.title(title, fontsize=22) # plot the inset if inset_results_file is not None: inset_ax = plt.axes([.66, .10, .3, .34]) inset_headers, inset_labels, inset_ys = read_results_file( inset_results_file) if order is not None: new_inset_ys = [] for catid, catname in order: new_inset_ys.append(inset_ys[cats.index(catid)]) inset_ys = new_inset_ys draw_boxes(inset_ys, inset_ax) inset_ax.axes.get_xaxis().set_visible(False) if inset_title is not None: inset_ax.set_title(inset_title) pp = PdfPages(dest) fig.savefig(pp, format='pdf') pp.close() plt.close()
def line_plot(result_file, dest, order=None, inset_result_file=None, inset_title=None, title=None, legend_pos=None, legend_cols=None, xlabel=None, ylabel=None): headers, labels, ys = read_results_file(result_file) cats = headers[1:] x = sorted([int(num_clicks) for num_clicks in labels]) # reorder the data that will be plotted and set legend labels legend_labels = [] if order is not None: new_ys = [] for catid, catname in order: new_ys.append(ys[cats.index(catid)]) legend_labels.append(catname) ys = new_ys else: legend_labels = cats[:] fig = plt.figure() ax = fig.add_subplot(111) colors = ['#fdb863', '#e66101', '#b2abd2', '#5e3c99'] markers = ['s', 'o', '^', 'x'] curves = [] for i in range(len(ys)): curve = ax.plot(x, ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] #curve = ax.errorbar(x, ys[i], errors[i], color=colors[i]) curves.append(curve) # display a subfigure id if this is going to be part of a subfigure plt.figtext(0.025, 0.025, "b", fontsize=30, weight='bold') legend_str = legend_pos if legend_pos is not None else "upper right" cols = legend_cols if legend_cols is not None else 2 ax.legend(curves, legend_labels, loc=legend_str, shadow=False, ncol=cols, prop=FontProperties(size=18), numpoints=1) plt.xlim(x[0] - .2 * x[0], x[-1] + .9 * x[-1]) #plt.ylim(ys[0][0] - .2 * ys[0][0], ys[0][-1] + .05 * ys[0][-1]) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(22) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(22) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=22) if ylabel is not None: ax.set_ylabel(ylabel, fontsize=22) if title is not None: plt.title(title, fontsize=22) ax.set_xscale('log') plt.grid(True, color="#bbbbbb") # add an inset to the figure if inset_result_file is not None: inset_ax = plt.axes([.6, .2, .35, .26]) inset_headers, inset_labels, inset_ys = read_results_file( inset_result_file) inset_x = sorted([int(num_clicks) for num_clicks in inset_labels]) # reorder the data that will be plotted and set legend labels if order is not None: new_inset_ys = [] for catid, catname in order: new_inset_ys.append(inset_ys[cats.index(catid)]) inset_ys = new_inset_ys inset_curves = [] for i in range(len(inset_ys)): curve = inset_ax.plot(inset_x, inset_ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] inset_curves.append(curve) inset_ax.set_xscale('log') if inset_title is not None: inset_ax.set_title(inset_title) pp = PdfPages(dest) fig.savefig(pp, format='pdf') pp.close() plt.close()
def line_plot(result_file, dest, inset_result_file=None, inset_title=None, order=None, title=None, legend_pos=None, legend_cols=None, xlabel=None, ylabel=None): headers, labels, ys = read_results_file(result_file) cats = headers[1:] # reorder the data that will be plotted and set legend labels legend_labels = [] if order is not None: new_ys = [] for catid, catname in order: new_ys.append(ys[cats.index(catid)]) legend_labels.append(catname) ys = new_ys else: legend_labels = cats[:] #labels, ys = fill_missing_values(labels, ys) x = range(len(labels)) fig = plt.figure() ax = fig.add_subplot(111) colors = ['#fdb863', '#e66101', '#b2abd2', '#5e3c99'] markers = ['s', 'o', '^', 'x'] curves = [] for i in range(len(ys)): curve = ax.plot(x, ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] # to plot the error bars, the error needs to be computed and be place in the same file as the results being plotted #ax.errorbar(x, ys[i], errors[i], color=colors[i]) curves.append(curve) legend_str = legend_pos if legend_pos is not None else "upper right" cols = legend_cols if legend_cols is not None else 2 ax.legend(curves, legend_labels, shadow=False, ncol=cols, prop=FontProperties(size=12), numpoints=1, bbox_to_anchor=(-.04, 0.02, 0.30, .2)) # display a subfigure id if this is going to be part of a subfigure plt.figtext(0.025, 0.025, "b", fontsize=30, weight='bold') nice_labels = create_nice_labels(labels) xreduced = [] labels_reduced = [] count = 0 for i in range(len(x)): count += 1 if count % 2 == 0: xreduced.append(x[i]) labels_reduced.append(nice_labels[i]) plt.xticks(xreduced, labels_reduced, rotation=60) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(16) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(22) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=22) if ylabel is not None: ax.set_ylabel(ylabel, fontsize=22) if title is not None: plt.title(title, fontsize=22) plt.grid(True, color="#bbbbbb") # add an inset to the figure if inset_result_file is not None: inset_ax = plt.axes([.385, .2, .45, .23]) inset_headers, inset_labels, inset_ys = read_results_file( inset_result_file) inset_x = sorted(range(len(inset_labels))) # reorder the data that will be plotted and set legend labels if order is not None: new_inset_ys = [] for catid, catname in order: new_inset_ys.append(inset_ys[cats.index(catid)]) inset_ys = new_inset_ys inset_curves = [] for i in range(len(inset_ys)): curve = inset_ax.plot(inset_x, inset_ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] inset_curves.append(curve) inset_ax.axes.get_xaxis().set_visible(False) if inset_title is not None: inset_ax.set_title(inset_title) pp = PdfPages(dest) fig.savefig(pp, format='pdf') pp.close() plt.close()
def line_plot(result_file, dest, inset_result_file=None, inset_title=None, order=None, title=None, legend_pos=None, legend_cols=None, xlabel=None, ylabel=None): headers, labels, ys = read_results_file(result_file) cats = headers[1:] # reorder the data that will be plotted and set legend labels legend_labels = [] if order is not None: new_ys = [] for catid, catname in order: new_ys.append(ys[cats.index(catid)]) legend_labels.append(catname) ys = new_ys else: legend_labels = cats[:] #labels, ys = fill_missing_values(labels, ys) x = range(len(labels)) fig = plt.figure() ax = fig.add_subplot(111) colors = ['#fdb863', '#e66101', '#b2abd2', '#5e3c99'] markers = ['s', 'o', '^', 'x'] curves = [] for i in range(len(ys)): curve = ax.plot(x, ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] # to plot the error bars, the error needs to be computed and be place in the same file as the results being plotted #ax.errorbar(x, ys[i], errors[i], color=colors[i]) curves.append(curve) legend_str = legend_pos if legend_pos is not None else "upper right" cols = legend_cols if legend_cols is not None else 2 ax.legend(curves, legend_labels, shadow=False, ncol=cols, prop=FontProperties(size=12), numpoints=1, bbox_to_anchor=(-.04, 0.02, 0.30, .2)) # display a subfigure id if this is going to be part of a subfigure plt.figtext(0.025, 0.025, "b", fontsize=30, weight='bold') nice_labels = create_nice_labels(labels) xreduced = [] labels_reduced = [] count = 0 for i in range(len(x)): count += 1 if count % 2 == 0: xreduced.append(x[i]) labels_reduced.append(nice_labels[i]) plt.xticks(xreduced, labels_reduced, rotation=60) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(16) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(22) if xlabel is not None: ax.set_xlabel(xlabel, fontsize=22) if ylabel is not None: ax.set_ylabel(ylabel, fontsize=22) if title is not None: plt.title(title, fontsize=22) plt.grid(True, color="#bbbbbb") # add an inset to the figure if inset_result_file is not None: inset_ax = plt.axes([.385, .2, .45, .23]) inset_headers, inset_labels, inset_ys = read_results_file(inset_result_file) inset_x = sorted(range(len(inset_labels))) # reorder the data that will be plotted and set legend labels if order is not None: new_inset_ys = [] for catid, catname in order: new_inset_ys.append(inset_ys[cats.index(catid)]) inset_ys = new_inset_ys inset_curves = [] for i in range(len(inset_ys)): curve = inset_ax.plot(inset_x, inset_ys[i], linestyle="-", color=colors[i], marker=markers[i], markerfacecolor='none', markeredgecolor=colors[i])[0] inset_curves.append(curve) inset_ax.axes.get_xaxis().set_visible(False) if inset_title is not None: inset_ax.set_title(inset_title) pp = PdfPages(dest) fig.savefig(pp, format='pdf') pp.close() plt.close()