def _ratioFigure(self): self.axR = plt.subplot(self.gs[1]) for i, ratio in enumerate(self.ratios): if self.plotType[i] == 'Data': rplt.errorbar(ratio, label=self.label[i], markerfacecolor=self.colour[i], markersize=8, xerr=False, yerr=False, elinewidth=0, markeredgewidth=0, markeredgecolor=self.colour[i], emptybins=False, zorder=self.zorder[i], axes=self.axR) elif self.plotType[i] == 'CMSSW': rplt.step(ratio, label=self.label[i], color=self.colour[i], zorder=self.zorder[i], linewidth=2, axes=self.axR) elif self.plotType[i] == 'Simulation': plt.axhline(y=1, color='black', linewidth=2, axes=self.axR) else: pass return None
def _plotFigure(self): self.ax = plt.subplot(self.gs[0]) for i, hist in enumerate(self.hists): if self.plotType[i] == 'Data': rplt.errorbar(hist, label=self.label[i], markerfacecolor=self.colour[i], markersize=8, xerr=False, yerr=False, elinewidth=0, markeredgewidth=0, markeredgecolor=self.colour[i], emptybins=False, zorder=self.zorder[i], axes=self.ax) elif self.plotType[i] == 'Simulation': rplt.hist(hist, label=self.label[i], color=self.colour[i], alpha=self.alpha[i], fill=self.fill[i], zorder=self.zorder[i], axes=self.ax) elif self.plotType[i] == 'CMSSW': rplt.step(hist, label=self.label[i], color=self.colour[i], zorder=self.zorder[i], linewidth=2, axes=self.ax) else: pass return None
def make_data_mc_comparison_plot( histograms=[], histogram_lables=[], histogram_colors=[], histogram_properties=Histogram_properties(), data_index=0, save_folder='plots/', save_as=['pdf'], normalise=False, show_ratio=False, show_stat_errors_on_mc=False, draw_vertical_line=0, systematics_for_ratio=None, systematics_for_plot=None, histograms_to_compare=None, ): ''' systematics_for_plot takes the same input as systematics_for_ratio. There may be some repition with reagrds to mc_error and mc_relative_errors, but these only deal with a flat error up and down. ''' save_folder = check_save_folder(save_folder) # make copies in order not to mess with existing histograms histograms_ = deepcopy(histograms) stack = HistStack() add_mc = stack.Add for index, histogram in enumerate(histograms_): label = histogram_lables[index] color = histogram_colors[index] histogram.SetTitle(label) if normalise: histogram.Sumw2() if not index == data_index: histogram.fillstyle = 'solid' histogram.fillcolor = color histogram.legendstyle = 'F' add_mc(histogram) data = histograms_[data_index] data.SetMarkerSize(CMS.data_marker_size) if normalise: n_events_data = data.Integral() n_events_mc = stack.Integral() data.Scale(1 / n_events_data) stack.Scale(1 / n_events_mc) # plot with matplotlib plt.figure(figsize=CMS.figsize, dpi=CMS.dpi, facecolor=CMS.facecolor) axes = None if show_ratio: ratio = data.Clone('ratio') sumHists = sum(stack.GetHists()) for bin_i in range(1, sumHists.GetNbinsX()): sumHists.SetBinError(bin_i, 0) ratio.Divide(sum(stack.GetHists())) ratio.SetMarkerSize(3) gs = gridspec.GridSpec(2, 1, height_ratios=[5, 1]) axes = plt.subplot(gs[0]) else: axes = plt.axes() if histogram_properties.set_log_y: axes.set_yscale('log', nonposy="clip") axes.set_ylim(ymin=1e-2) if systematics_for_plot != None: plusErrors = [x + 1 for x in systematics_for_plot] minusErrors = [1 - x for x in systematics_for_plot] stack_lower = sum(stack.GetHists()) stack_upper = stack_lower.Clone('upper') for bin_i in range(1, stack_lower.GetNbinsX() + 1): central_value = stack_lower.GetBinContent(bin_i) error_upper_bound = plusErrors[bin_i - 1] * central_value error_lower_bound = minusErrors[bin_i - 1] * central_value stack_upper.SetBinContent(bin_i, error_upper_bound) stack_lower.SetBinContent(bin_i, error_lower_bound) rplt.fill_between( stack_lower, stack_upper, axes, hatch='//', # facecolor = 'Black', facecolor='None', edgecolor='Grey', alpha=1., linewidth=0., zorder=len(histograms_) + 1) mc_error = histogram_properties.mc_error mc_relative_errors = histogram_properties.mc_relative_errors if mc_relative_errors: stack_lower = sum(stack.GetHists()) stack_upper = stack_lower.Clone('upper') for bin_i in range(1, stack_lower.GetNbinsX()): central_value = stack_lower.GetBinContent(bin_i) relative_error = mc_relative_errors[bin_i - 1] error_upper_bound = central_value * (1 + relative_error) error_lower_bound = central_value * (1 - relative_error) stack_lower.SetBinContent(bin_i, error_upper_bound) stack_upper.SetBinContent(bin_i, error_lower_bound) rplt.fill_between(stack_upper, stack_lower, axes, facecolor='0.75', alpha=0.5, hatch='/', zorder=len(histograms_) + 1) else: if mc_error > 0: stack_lower = sum(stack.GetHists()) stack_upper = stack_lower.Clone('upper') stack_lower.Scale(1 - mc_error) stack_upper.Scale(1 + mc_error) rplt.fill_between(stack_upper, stack_lower, axes, facecolor='0.75', alpha=0.5, hatch='/', zorder=len(histograms_) + 1) if not mc_error > 0 and show_stat_errors_on_mc: stack_lower = sum(stack.GetHists()) mc_errors = list(stack_lower.yerravg()) stack_upper = stack_lower.Clone('upper') for bin_i in range(1, stack_lower.GetNbinsX()): central_value = stack_lower.GetBinContent(bin_i) error = mc_errors[bin_i - 1] error_upper_bound = central_value + error error_lower_bound = central_value - error stack_lower.SetBinContent(bin_i, error_lower_bound) stack_upper.SetBinContent(bin_i, error_upper_bound) rplt.fill_between(stack_upper, stack_lower, axes, facecolor='0.75', alpha=0.5, hatch='/', zorder=len(histograms_) + 1) # a comment on zorder: the MC stack should be always at the very back (z = 1), # then the MC error (z = len(histograms_) + 1) and finally the data # (z = len(histograms_) + 2) rplt.hist(stack, stacked=True, axes=axes, zorder=1) rplt.errorbar(data, emptybins=histogram_properties.emptybins, axes=axes, xerr=histogram_properties.xerr, elinewidth=2, capsize=10, capthick=2, zorder=len(histograms_) + 2) if histograms_to_compare: h_compare = {} for h, l, c in zip(histograms_to_compare['hists'], histograms_to_compare['labels'], histograms_to_compare['colours']): for histogram in histograms_: if histogram.GetTitle() not in [ histograms_to_compare['to_replace'], 'data' ]: h += histogram h_compare[l] = [h, c] rplt.step( h, axes=axes, label=l, color=c, linewidth=4, ) # put legend into the correct order (data is always first!) handles, labels = axes.get_legend_handles_labels() data_label_index = labels.index('data') data_handle = handles[data_label_index] labels.remove('data') handles.remove(data_handle) labels.insert(0, 'data') handles.insert(0, data_handle) if mc_error > 0 or (not mc_error > 0 and show_stat_errors_on_mc): p1 = Rectangle((0, 0), 1, 1, fc="0.75", alpha=0.5, hatch='/') handles.append(p1) labels.append(histogram_properties.mc_errors_label) l1 = axes.legend(handles, labels, numpoints=1, frameon=histogram_properties.legend_color, bbox_to_anchor=histogram_properties.legend_location, bbox_transform=plt.gcf().transFigure, prop=CMS.legend_properties, ncol=histogram_properties.legend_columns) l1.set_zorder(102) set_labels(plt, histogram_properties, show_x_label=not show_ratio, axes=axes) x_limits = histogram_properties.x_limits y_limits = histogram_properties.y_limits if len(x_limits) >= 2: axes.set_xlim(xmin=x_limits[0], xmax=x_limits[-1]) if len(y_limits) >= 2: axes.set_ylim(ymin=y_limits[0], ymax=y_limits[-1]) else: y_max = get_best_max_y( histograms_, x_limits=x_limits) * histogram_properties.y_max_scale print("Chosen limits : ", 0, y_max) axes.set_ylim(ymin=0, ymax=y_max) if histogram_properties.set_log_y: if not len(y_limits) == 2: # if not user set y-limits, set default axes.set_ylim(ymin=1e-1) #draw a red vertical line if needed: if draw_vertical_line != 0: plt.axvline(x=draw_vertical_line, color='red', linewidth=3) if show_ratio: plt.setp(axes.get_xticklabels(), visible=False) ax1 = plt.subplot(gs[1]) ax1.minorticks_on() ax1.grid(True, 'major', linewidth=1) ax1.axhline(y=1, linewidth=1) set_labels(plt, histogram_properties, show_x_label=True, show_title=False) plt.ylabel(r'$\frac{\mathrm{data}}{\mathrm{pred.}}$', CMS.y_axis_title) ax1.yaxis.set_label_coords(-0.115, 0.8) rplt.errorbar(ratio, emptybins=histogram_properties.emptybins, axes=ax1, xerr=histogram_properties.xerr, elinewidth=1.5, capsize=5, capthick=1.5) if histograms_to_compare: for l, h in h_compare.iteritems(): r = data.Clone(l).Divide(h[0]) rplt.step( r, axes=ax1, label='', colour=h[1], linewidth=2, ) if len(x_limits) >= 2: ax1.set_xlim(xmin=x_limits[0], xmax=x_limits[-1]) if len(histogram_properties.ratio_y_limits) >= 2: ax1.set_ylim(ymin=histogram_properties.ratio_y_limits[0], ymax=histogram_properties.ratio_y_limits[-1]) # dynamic tick placement adjust_ratio_ticks(ax1.yaxis, n_ticks=3, y_limits=histogram_properties.ratio_y_limits) if histogram_properties.integerXVariable: ax1.tick_params(axis='x', which='minor', bottom='off', top='off') if systematics_for_ratio != None: plusErrors = [x + 1 for x in systematics_for_ratio] minusErrors = [1 - x for x in systematics_for_ratio] ratioPlusError = ratio.Clone('plus') ratioMinusError = ratio.Clone('minus') for bin_i in range(1, ratioPlusError.GetNbinsX() + 1): ratioPlusError.SetBinContent(bin_i, plusErrors[bin_i - 1]) ratioMinusError.SetBinContent(bin_i, minusErrors[bin_i - 1]) rplt.fill_between( ratioPlusError, ratioMinusError, axes, hatch='//', # facecolor = 'Black', facecolor='None', edgecolor='Grey', alpha=1., linewidth=0., # zorder = len(histograms_) + 1 zorder=0) if CMS.tight_layout: plt.tight_layout() for save in save_as: if save == 'root': saveHistogramsToROOTFile( data, stack, save_folder + histogram_properties.name + '.' + save) else: plt.savefig(save_folder + histogram_properties.name + '.' + save) plt.close()
h1b, h1c, h1u = get_hists( dd2, (dd2["is_training"] == 0) & (abs(dd2["Jet_eta"]) >= etalow) & (abs(dd2["Jet_eta"]) < etahigh), "cls_p0", (200, 0, 1)) h2b, h2c, h2u = get_hists( dd2, (dd2["is_training"] == 1) & (abs(dd2["Jet_eta"]) >= etalow) & (abs(dd2["Jet_eta"]) < etahigh), "cls_p0", (200, 0, 1)) for h in [h1b, h2b, h1c, h2c, h1u, h2u]: h.Scale(1.0 / h.Integral()) plt.figure(figsize=(9, 3)) plt.title("Discriminator plots, " + str(etalow) + " < $|\eta|$ < " + str(etahigh)) plt.subplot(1, 3, 1) rplt.step(h1b, color="red", label="testing") rplt.step(h2b, color="blue", label="training") plt.xlabel("discriminator") plt.ylabel("fraction of jets") plt.title("b") plt.yscale("log") plt.legend(loc="best") plt.subplot(1, 3, 2) rplt.step(h1c, color="red") rplt.step(h2c, color="blue") plt.xlabel("discriminator") plt.ylabel("fraction of jets") plt.title("charm") plt.yscale("log")
def plot_cmssw_charge_occupancy_variations(REGION, useFullDist=True): ''' Data highOcc vs SCD vs SCD Po(N) ''' make_folder_if_not_exists('plots/InputChargePoissonMatching/') OCC = REGION_DETAILS[REGION]['Occ_Data'] hs_to_plot = [] rs_to_plot = [] occupancies_to_test = [] colors = ['blue', 'red', 'darkgreen', 'magenta'] if useFullDist: f_hist = 'input/landau_scd_290118_orig.root' occupancies_to_test = [OCC * 10, OCC * 20, OCC * 50, OCC * 100] else: f_hist = 'input/landau_scd_290118_cut.root' occupancies_to_test = [OCC * 5, OCC * 10, OCC * 20, OCC * 50] with root_open(f_hist) as f: h = asrootpy(f.Get(REGION).Clone()) h.SetDirectory(0) l_edges = list(h.xedges()) # with root_open('input/landau_lowPUTracks_290118_orig.root') as f: # h_data_PU0 = asrootpy(f.Get(REGION).Clone()) # h_data_PU0.SetDirectory(0) # h_data_PU0.Scale(1 /h_data_PU0.integral(xbin1=21,xbin2=200)) # hs_to_plot.append({ # 'hist' : h_data_PU0, # 'label' : 'lowPU Strips from Tracks', # # 'color' : '0.5', # 'color' : 'grey', # 'type' : 'Data' # }) # with root_open('input/landau_lowPUClusters_290118_orig.root') as f: # h_data_lowOcc = asrootpy(f.Get(REGION).Clone()) # h_data_lowOcc.SetDirectory(0) # h_data_lowOcc.Scale(1 /h_data_lowOcc.integral(xbin1=21,xbin2=200)) # hs_to_plot.append({ # 'hist' : h_data_lowOcc, # 'label' : 'lowOcc Strips from Clusters', # # 'color' : '0', # 'color' : 'brown', # 'type' : 'Data' # }) with root_open( 'input/landau_clusterData_010218_VFPFix_True_orig.root') as f: h_data_highOcc = asrootpy(f.Get(REGION).Clone()) h_data_highOcc.SetDirectory(0) h_data_highOcc.Scale(1 / h_data_highOcc.integral(xbin1=21, xbin2=200)) hs_to_plot.append({ 'hist': h_data_highOcc, 'label': 'highOcc Strips from Clusters', # 'color' : '0', 'color': 'black', 'type': 'Data' }) hist_scd = Hist(l_edges) h_tests = [] for occ, col in zip(occupancies_to_test, colors): h_tmp = { 'occ': occ, 'hist': Hist(l_edges), 'color': col, } h_tests.append(h_tmp) i = 0 while i < 250000: v = return_strip_charge_from_Poisson(h, OCC, add_noise=False, add_truncation=True) hist_scd.Fill(v) for h_test in h_tests: v_occ = return_strip_charge_from_Poisson(h, h_test['occ'], add_noise=False, add_truncation=True, cut_charge=True) if not v_occ < 10000: h_test['hist'].Fill(v_occ) i = i + 1 # Normalising between 10000-100000 hist_scd.Scale(1 / hist_scd.integral(xbin1=21, xbin2=200)) for h_test in h_tests: h_test['hist'].Scale(1 / h_test['hist'].integral(xbin1=21, xbin2=200)) scd = '' if useFullDist: scd = 'SCD' else: scd = 'Cut SCD' r_scd = h_data_highOcc.Clone() r_scd.SetDirectory(0) r_scd.Divide(hist_scd) hs_to_plot.append({ 'hist': hist_scd, 'label': '{SCD} sampled Po({OCC})'.format(SCD=scd, OCC=OCC), 'color': 'black', 'type': 'SCD' }) rs_to_plot.append({ 'hist': r_scd, 'label': '', 'color': 'black', 'type': 'Ratio' }) for h_test in h_tests: r = h_data_highOcc.Clone() r.SetDirectory(0) r.Divide(h_test['hist']) hs_to_plot.append({ 'hist': h_test['hist'], 'label': '{SCD} sampled Po({OCC})'.format(SCD=scd, OCC=h_test['occ']), 'color': h_test['color'], 'line': 'solid', 'type': 'CMSSW' }) rs_to_plot.append({ 'hist': r, 'label': '', 'color': h_test['color'], 'type': 'Ratio' }) fig = plt.figure() fig.suptitle( "Charge Deposition from Simulation using Sampling from {SCD} distribution" .format(SCD=scd), fontsize=14, fontweight='bold') gs = gridspec.GridSpec(2, 1, height_ratios=[5, 1], wspace=0.025, hspace=0.025) ax = plt.subplot(gs[0]) plt.title(REGION.replace("_", " ") + " normalised 10,000-70,000", loc='right') for h_info in hs_to_plot: if 'Data' in h_info['type']: rplt.hist( h_info['hist'], label=h_info['label'], color=h_info['color'], alpha=0.35, fill=True, zorder=0, ) if 'SCD' in h_info['type']: rplt.errorbar( h_info['hist'], label=h_info['label'], markerfacecolor=h_info['color'], markersize=3, xerr=False, yerr=False, elinewidth=0, emptybins=False, zorder=len(hs_to_plot), ) if 'CMSSW' in h_info['type']: rplt.step(h_info['hist'], label=h_info['label'], color=h_info['color'], linestyle=h_info['line']) ax.set_ylim([0.0001, 1.]) # ax.set_xlim([10000,70000]) ax.set_xlim([0.1, 70000]) ax.set_yscale("log", nonposy='clip') ax.set_ylabel('N') # ax.set_xlabel('Charge (e)') plt.setp(ax.get_xticklabels(), visible=False) leg = ax.legend(loc='upper right', numpoints=1, prop={'size': 10}, ncol=2) leg.draw_frame(False) ax_ratio = plt.subplot(gs[1]) ax_ratio.axhline(1, color='black') for r_info in rs_to_plot: rplt.errorbar( r_info['hist'], label=r_info['label'], markerfacecolor=r_info['color'], markersize=6, markeredgewidth=0, xerr=False, yerr=False, elinewidth=0, emptybins=False, axes=ax_ratio, ) ax_ratio.set_ylim([0, 2]) ax_ratio.set_xlim([0.1, 70000]) # ax_ratio.set_xlim([10000,70000]) ax_ratio.set_xlabel('Charge deposited on APV in a bx(e) ') ax_ratio.set_ylabel( r'$\frac{\mathrm{Data\ High\ Occ}}{\mathrm{SCD\ Sampling}}$') gs.tight_layout(fig, rect=[0, 0.03, 1, 0.95]) filename = 'CMSSWSimChargeFrom{SCD}_'.format( SCD=scd.replace(" ", "")) + REGION fig.savefig('plots/InputChargePoissonMatching/' + filename + '.pdf', bbox_inches='tight') fig.clf() plt.close() gc.collect()
def plot_cmssw_data_charge_comparisons(REGION): ''' SCD vs CMSSWSimPostAPV lowOcc vs Data lowOcc vs Data highOcc ''' make_folder_if_not_exists('plots/InputChargeComparisons/') hs_to_plot = [] rs_to_plot = [] with root_open('input/180207/landau_Sim_scd_070218.root') as f: h_scd = asrootpy(f.Get('demo/SCD/' + REGION).Clone()) h_scd = apply_max_cutoff(h_scd) h_scd.Scale(1 / h_scd.integral(xbin1=21, xbin2=200)) h_scd.SetDirectory(0) hs_to_plot.append({ 'hist': h_scd, 'label': 'SCD', 'color': 'black', 'type': 'SCD' }) h_clus = asrootpy(f.Get('demo/Clusters/' + REGION).Clone()) h_clus.Scale(1 / h_clus.integral(xbin1=21, xbin2=200)) h_clus.SetDirectory(0) hs_to_plot.append({ 'hist': h_clus, 'label': 'Cluster Strip Charge', 'color': 'red', 'line': 'solid', 'type': 'CMSSW' }) with root_open( 'input/180129_lowPU/landau_lowPUClusters_290118_orig.root') as f: h_data_lowOcc = asrootpy(f.Get(REGION).Clone()) h_data_lowOcc.Scale(1 / h_data_lowOcc.integral(xbin1=21, xbin2=200)) h_data_lowOcc.SetDirectory(0) hs_to_plot.append({ 'hist': h_data_lowOcc, 'label': 'Data lowOcc Strips from Clusters', 'color': 'black', 'type': 'Data' }) r = h_data_lowOcc.Clone() r.SetDirectory(0) r.Divide(h_scd) r2 = h_data_lowOcc.Clone() r2.SetDirectory(0) r2.Divide(h_clus) rs_to_plot.append({ 'hist': r, 'label': '', 'color': 'black', 'type': 'Ratio' }) rs_to_plot.append({ 'hist': r2, 'label': '', 'color': 'red', 'type': 'Ratio' }) fig = plt.figure() fig.suptitle( "Low PU: SCD vs CMSSW Cluster Strip Charge vs Data Cluster Strip Charge", fontsize=14, fontweight='bold') gs = gridspec.GridSpec(2, 1, height_ratios=[5, 1], wspace=0.025, hspace=0.025) ax = plt.subplot(gs[0]) plt.title(REGION.replace("_", " ") + " normalised 10,000-70,000", loc='right') for h_info in hs_to_plot: if 'Data' in h_info['type']: rplt.hist( h_info['hist'], label=h_info['label'], color=h_info['color'], alpha=0.35, fill=True, zorder=0, ) if 'SCD' in h_info['type']: rplt.errorbar( h_info['hist'], label=h_info['label'], markerfacecolor=h_info['color'], markersize=3, xerr=False, yerr=False, elinewidth=0, emptybins=False, zorder=len(hs_to_plot), ) if 'CMSSW' in h_info['type']: rplt.step(h_info['hist'], label=h_info['label'], color=h_info['color'], linestyle=h_info['line']) ax.set_ylim([0.0001, 1.]) ax.set_xlim([0.1, 70000]) ax.set_yscale("log", nonposy='clip') ax.set_ylabel('N') plt.setp(ax.get_xticklabels(), visible=False) leg = ax.legend(loc='upper right', numpoints=1, prop={'size': 10}, ncol=1) leg.draw_frame(False) ax_ratio = plt.subplot(gs[1]) ax_ratio.axhline(1, color='black') for r_info in rs_to_plot: rplt.errorbar( r_info['hist'], label=r_info['label'], markerfacecolor=r_info['color'], markersize=3, markeredgewidth=0, xerr=False, yerr=False, elinewidth=0, emptybins=False, axes=ax_ratio, ) ax_ratio.set_ylim([0, 2]) ax_ratio.set_xlim([0.1, 70000]) ax_ratio.set_xlabel('Charge deposited on APV in a bx(e) ') ax_ratio.set_ylabel(r'$\frac{\mathrm{Data}}{\mathrm{Sim}}$') gs.tight_layout(fig, rect=[0, 0.03, 1, 0.95]) filename = 'CMSSWSimChargeDepositionVsData' + REGION fig.savefig('plots/InputChargeComparisons/' + filename + '.png', bbox_inches='tight') fig.clf() plt.close() gc.collect()
def plot_cmssw_charge_distributions(REGION): ''' CMSSWSim stages. SCD vs SCD+Noise+ZS vs SCD+Noise+ZS+ClusterStripsOnly ''' make_folder_if_not_exists('plots/InputChargeDistributionsCMSSW/') hs_to_plot = [] with root_open('input/180207/landau_Sim_scd_070218.root') as f: h_scd = asrootpy(f.Get('demo/SCD/' + REGION).Clone()) h_scd = apply_max_cutoff(h_scd) h_scd.Scale(1 / h_scd.integral(xbin1=21, xbin2=200)) h_scd.SetDirectory(0) hs_to_plot.append({ 'hist': h_scd, 'label': 'SCD', 'color': 'black', 'type': 'CMSSW' }) h_zs = asrootpy(f.Get('demo/ZS/' + REGION).Clone()) h_zs = apply_max_cutoff(h_zs) h_zs.Scale(1 / h_zs.integral(xbin1=21, xbin2=200)) h_zs.SetDirectory(0) hs_to_plot.append({ 'hist': h_zs, 'label': 'SCD + Noise + ZS', 'color': 'blue', 'type': 'CMSSW' }) h_clus = asrootpy(f.Get('demo/Clusters/' + REGION).Clone()) h_clus.Scale(1 / h_clus.integral(xbin1=21, xbin2=200)) h_clus.SetDirectory(0) hs_to_plot.append({ 'hist': h_clus, 'label': 'Cluster Strip Charge', 'color': 'red', 'type': 'CMSSW' }) fig = plt.figure() fig.suptitle("Evolution of the SCD in CMSSW", fontsize=14, fontweight='bold') gs = gridspec.GridSpec(1, 1, wspace=0.025, hspace=0.025) ax = plt.subplot(gs[0]) plt.title(REGION.replace("_", " ") + " normalised between 10,000-70,000", loc='right') for h_info in hs_to_plot: if 'CMSSW' in h_info['type']: rplt.step( h_info['hist'], label=h_info['label'], color=h_info['color'], ) ax.set_ylim([0.0001, 10.]) ax.set_xlim([0, 70000]) ax.set_yscale("log", nonposy='clip') ax.set_ylabel('N') ax.set_xlabel('Charge (e)') leg = ax.legend(loc='best', numpoints=1, prop={'size': 10}) leg.draw_frame(False) gs.tight_layout(fig, rect=[0, 0.03, 1, 0.95]) filename = 'CMSSWSimChargeDepositionOrig' + REGION fig.savefig('plots/InputChargeDistributionsCMSSW/' + filename + '.png', bbox_inches='tight') fig.clf() plt.close() gc.collect()