def compare_violins(results, base_pdf = None): if not isinstance(results, dict): combined = aggregate_results(results) else: combined = results for obs in combined: figure = plt.figure() norms = None handles = [] plt.title(str(obs), y=1.05) colors = plotutils.color_names_to_rgb(colorlist) alpha = 1 base = combined[obs].get(base_pdf, None) results = sorted(combined[obs].values(), key = lambda x: x!=base) for result in results: if base is not None: cv = base.central_value.as_matrix() data = result._violin_data(rel_to=cv) else: data = data = result._violin_data() color = next(colors) + (alpha,) alpha /= 2 plot, handle, norms = result.violin_plot(data, color=color, showextrema=False, normvalues=norms) handles.append(handle) plt.xlabel('bins') if base_pdf: plt.ylabel('Ratio to %s' % base_pdf.label) else: plt.ylabel("Observable value") plt.xticks(range(1,len(result.central_value) + 1)) #Small style dfs = plt.yticks()[0] - 1 l = len(dfs) // 2 + 1 - ((len(dfs) // 2) % 2) mdiff = np.max(dfs) plt.yticks(np.linspace(-mdiff, mdiff, l) + 1) # plt.legend(handles=handles) yield (obs,), figure
def compare_cis(results, base_pdf = None): if not isinstance(results, dict): combined = aggregate_results(results) else: combined = results for obs in combined: figure = plt.figure() colors = plotutils.color_names_to_rgb(colorlist) plt.title(str(obs), y=1.05) base = combined[obs].get(base_pdf, None) results = sorted(combined[obs].values(), key = lambda x: x!=base) l = len(results) if l < 5: delta = iter(np.linspace(-0.05*l, 0.05*l, l)) else: delta = iter(np.linspace(-0.25, 0.25, l)) #x = iter(np.arange(1, len(results) + 1)) for result in results: x = np.arange(1, result.nbins+1) + next(delta) #Without copy the /= operator affects the underlying data. data_cv = result.central_value.as_matrix().copy() data_ci = result.errorbar68.as_matrix().copy() if base is not None: base_cv = base.central_value.as_matrix() data_cv /= base_cv data_ci /= base_cv[:,np.newaxis] data_ci = np.abs(data_ci) color = next(colors) plt.errorbar(x, data_cv, yerr=data_ci.T, linestyle='none', color=color, label=result.pdf.label, elinewidth = 2, capsize=10) if isinstance(result, MCResult): #Without copy the /= operator affects the underlying data. data_std = result.rel_std_interval().as_matrix().copy() if base is not None: data_std /= base_cv[:,np.newaxis] data_std = np.abs(data_std) plt.errorbar(x, data_cv, yerr=data_std.T, linestyle='none', color=color, elinewidth = 2, capsize=15) plt.xlabel('bins') if base_pdf: plt.ylabel('Ratio to %s' % base_pdf.label) else: plt.ylabel("Observable value") plt.xticks(range(1,len(result.central_value) + 1)) plt.legend() plt.xlim(0.5, results[0].nbins + 0.5) plt.grid(axis='x') #Small style dfs = plt.yticks()[0] - 1 l = len(dfs) // 2 + 1 - ((len(dfs) // 2) % 2) mdiff = np.max(dfs) plt.yticks(np.linspace(-mdiff, mdiff, l) + 1) yield (obs,), figure