def initialise_axes(axes,hists,options,filename=None): # hists is a list with potentially only one element # try: hists[0] # except:TypeError , hists=[hists] xmins = [ hist.xedges[0] for hist in hists ] ymins = [ hist.yedges[0] for hist in hists ] xmaxs = [ hist.xedges[-1] for hist in hists ] ymaxs = [ hist.yedges[-1] for hist in hists ] xmin, xmax, ymin, ymax = min(xmins), min(xmaxs), min(ymins), max(ymaxs) axes.set_xlabel( hists[0].xlabel ) axes.set_ylabel( hists[0].ylabel ) plt.axis( [xmin, xmax, ymin, ymax] ) if options.get("xlog") : axes.set_xscale('log') if options.get("ylog") : axes.set_yscale('log') if options.get('yticks') : pylab.yticks(pylab.arange( ymin, ymax*1.001, options["yticks"] ) ) if options.get('xticks') : pylab.xticks(pylab.arange( xmin, xmax*1.001, options["xticks"] ) ) if options.get('title') : if filename: # axes.set_title( file_dict.get(filename,{}).get('title')) title=file_dict.get(filename,{}).get('title') plt.text(0.5, 1.05, title, ha='center', fontsize=30,transform=axes.transAxes)
def plot_segments(axes,cs,options,filename=None,linestyle='solid'): from matplotlib.path import Path import matplotlib.patches as patches colors=options["colors"] # prepare labels for the legend!! labels=[] for i, level in enumerate(cs): label = None if file_dict.get(filename): label = file_dict[filename].get('label') if options.get('labels') is not None: label=options["labels"][i]+label else: if options.get('labels') is not None: label=options['labels'][i] labels.append(label) for i, level in enumerate(cs): for j,cont in enumerate(level): verts=[] codes=[Path.MOVETO] for coor in cont: verts.append((coor[0] ,coor[1] ) ) for vert in verts[1:]: codes.append(Path.LINETO) path = Path(verts, codes) if j ==0 : patch = patches.PathPatch(path,edgecolor=colors[i], facecolor='none', lw=2,linestyle=linestyle,label=labels[i]) else: patch = patches.PathPatch(path,edgecolor=colors[i], facecolor='none', lw=2,linestyle=linestyle) axes.add_patch(patch)
def make_single_1d_overlay( histos, filenames, ext="png" ) : #FIXME: ugly, but it does the job poorly linestyles=['dotted','solid','-.'] fs = [ r2m.RootFile(name) for name in filenames ] for hname, options in histos.iteritems() : fig = plt.figure( figsize=[10,7.5] ) plt.rcParams.update({'font.size':12,'axes.labelsize':30,'xtick.labelsize':25, 'ytick.labelsize':25 }) try: hists = [f.get(hname) for f in fs ] except ReferenceError: print "ERROR: {} is not in one of the files".format(hname) continue xmins =[ hist.xedges[0] for hist in hists ] xmaxs =[ hist.xedges[-1] for hist in hists ] xmin, xmax = min(xmins), max(xmaxs) ymin, ymax = options["zrange1d"] r_splines=[] for hist in hists : r_splines.append( get_raw_spline_from_hist(hist,options)) fig = plt.figure( figsize=[10,7.5] ) plt.axis( [xmin, xmax, ymin, ymax] ) axes = plt.axes() axes.set_xlabel( hist.xlabel ) axes.set_ylabel( options.get("ytitle",None) ) pylab.xticks(pylab.arange( xmin, xmax*1.001, options["xticks"] ) ) from config.file_dict import file_dict for rsp,lst,name in zip(r_splines,linestyles,filenames): (rxs,rys) = rsp plt.plot(rxs,rys,'b',linestyle=lst,linewidth=3,label=file_dict.get(name)) # plt.legend() plt.gcf().subplots_adjust(bottom=0.15) plt.gcf().subplots_adjust(left=0.15) print "Save to: ", fig_name( options, filenames[1] ) + "_overlay.%s" % ext plt.savefig( fig_name( options, filenames[1] ) + "_overlay.%s" % ext )
def initialise_axes(hist,options,xmin=None, xmax=None,ymin=None, ymax=None,filename=None, xmin_offset=0.): if xmin is None: xmin = hist.xedges[0] if xmax is None: xmax = hist.xedges[-1] if ymin is None and ymax is None: ymin,ymax = options["zrange1d"] plt.figure() # plt.rcParams.update({'font.size':18,}) fig = plt.figure( figsize=[10,7.5] ) # plt.rcParams.update({'font.size':25,'axes.labelsize':30 }) plt.rcParams.update({'axes.titlesize':30,'legend.fontsize':16,'axes.labelsize':35,'xtick.labelsize':25, 'ytick.labelsize':25 }) # plt.rcParams.update({'font.size':25,'axes.labelsize':30 }) plt.axis( [xmin, xmax, ymin, ymax] ) axes = plt.axes() axes.set_xlabel( hist.xlabel ) axes.set_ylabel( options["ytitle"] ) # axes.set_title( "%s(%s)" % (options["title"], hist.xlabel) ) pylab.xticks(pylab.arange( xmin+xmin_offset, xmax*1.001, options["xticks"] ) ) pylab.yticks(pylab.arange( ymin, ymax*1.001, options.get('yticks') ) ) if options.get('title') : if filename: # axes.set_title( file_dict.get(filename,{}).get('title')) title=file_dict.get(filename,{}).get('title') plt.text(0.5, 1.05, title, ha='center', fontsize=30,transform=axes.transAxes) return axes