def init_palette(): from rootpy.plotting.style import set_style, get_style atlas = get_style("ATLAS") atlas.SetPalette(51) set_style(atlas) return True
def main(parameters): style = get_style('CMSTDR') style.SetTitleSize(0.07, "XYZ") style.SetLegendBorderSize(0) style.SetLegendFillColor(0) style.SetLegendFont(43) style.SetTextSize(25) set_style(style) input_file = parameters.input_file plot_distributions(input_file, parameters.distribution_plots) plot_comparisons(input_file, parameters.comparison_plots)
def SetupATLAS(): rootpy.log.basic_config_colorized() #use latex for text rc('text', usetex=True) # set the style style = get_style('ATLAS') style.SetEndErrorSize(3) set_style(style) set_style('ATLAS', mpl=True) rc('font', family='sans-serif', weight='medium', size=16) rc('legend', fontsize=16)
def test_cmstdr(): style = get_style('CMSTDR') with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(100.) hpx.Draw()
def test_cmstdr(): style = get_style('CMSTDR') with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(100.) hpx.Draw() labels.CMS_label("Testing 2050", sqrts=100)
def test_atlas(): style = get_style('ATLAS') with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(80.) hpx.Draw() ATLAS_label(.4, .8)
def test_lhcb(): style = get_style('LHCb') with style: canvas = Canvas() hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(80.) hpx.Draw() LHCb_label("R", "preliminary") if INTERACTIVE: wait()
def set_hsg4_style(shape='square'): style = get_style('ATLAS', shape=shape) #style.SetFrameLineWidth(2) #style.SetLineWidth(2) #style.SetTitleYOffset(1.8) #style.SetTickLength(0.04, 'X') #style.SetTickLength(0.02, 'Y') # custom HSG4 modifications # style.SetPadTopMargin(0.06) style.SetPadLeftMargin(0.16) style.SetTitleYOffset(1.6) style.SetHistTopMargin(0.) style.SetHatchesLineWidth(1) style.SetHatchesSpacing(1) set_style(style)
def test_cmstdr(): style = get_style('CMSTDR') with style: canvas = Canvas() hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") ROOT.gRandom.SetSeed() for i in xrange(1000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(100.) hpx.Draw() CMS_label("Testing 2050", sqrts=100) if INTERACTIVE: wait()
def set_hsg4_style(shape='square'): style = get_style('ATLAS', shape=shape) #style.SetFrameLineWidth(2) #style.SetLineWidth(2) #style.SetTitleYOffset(1.8) #style.SetTickLength(0.04, 'X') #style.SetTickLength(0.02, 'Y') # custom HSG4 modifications # style.SetPadTopMargin(0.06) style.SetPadLeftMargin(0.16) style.SetTitleYOffset(1.6) style.SetHistTopMargin(0.) style.SetHatchesLineWidth(1) style.SetHatchesSpacing(1) ROOT.TGaxis.SetMaxDigits(4) set_style(style)
def MyStyle(): """customize ROOT style based on *CMSTDR* style""" style = get_style('CMSTDR') style.SetTitleSize(0.03, "XYZ") style.SetLabelSize(0.03, "XYZ") style.SetLegendBorderSize(0) style.SetLegendFillColor(0) font = 42 # Helvetica style.SetTextFont(font) style.SetLegendFont(43) style.SetPalette(ROOT.kBird) # 55 ROOT.kCMYK # 112 ROOT.kViridis style.SetErrorX() style.SetPadTopMargin(0.05) style.SetPadBottomMargin(0.10) style.SetPadLeftMargin(0.12) style.SetPadRightMargin(0.04) return style
def test_get_style(): mystyle = TStyle('mystyle', 'some style') assert(isinstance(get_style('mystyle'), Style))
def test_get_style(): mystyle = TStyle('mystyle', 'some style') assert (isinstance(get_style('mystyle'), Style))
def init_palette(): from rootpy.plotting.style import set_style, get_style atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) return True
def fithist(data,weightdata,central,eff=eff,plotDir=None): plotting = not (plotDir==None) if plotting and not os.path.exists(plotDir): print '== Making folder '+options.plotDir+' ==' os.makedirs(options.plotDir) if plotting: try: from rootpy.plotting.style import set_style, get_style print '== Using ATLAS style ==' atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) set_style('ATLAS',mpl=True) except ImportError: print '== Not using ATLAS style (Can\'t import rootpy.) ==' if plotting: n,bins,patches = plt.hist(data,normed=True,bins=100,weights=weightdata,facecolor='b',histtype='stepfilled') weightdata = weightdata/sum(weightdata) if central == 'absolute_median' or central == 'mode': if eff<0 or eff>1: raise RuntimeError('In order to use absolute IQR, you have to provide the reconstruction efficiency. Use --eff option.') (mu,mu_err,sigma,sigma_err,upper_quantile,lower_quantile,err) = distribution_values(data,weightdata,central,eff=eff) if plotting: plt.plot((mu,mu),(0,plt.ylim()[1]),'r--',linewidth=2) height = 0.607*max(n) #height at x=1*sigma in normal distribution if lower_quantile>float('-inf'): plt.plot((lower_quantile,upper_quantile),(height,height),'r--',linewidth=2) plt.plot((lower_quantile,lower_quantile),(height-0.02,height+0.02),'r-',linewidth=2) else: plt.plot((mu,upper_quantile),(height,height),'r--',linewidth=2) plt.plot((upper_quantile,upper_quantile),(height-0.02,height+0.02),'r-',linewidth=2) if central == 'median': (mu,mu_err,sigma,sigma_err,upper_quantile,lower_quantile) = distribution_values(data,weightdata,central) if plotting: plt.plot((mu,mu),(0,plt.ylim()[1]),'r--',linewidth=2) height = 0.607*max(n) #height at x=1*sigma in normal distribution plt.plot((lower_quantile,upper_quantile),(height,height),'r--',linewidth=2) plt.plot((lower_quantile,lower_quantile),(height-0.02,height+0.02),'r-',linewidth=2) plt.plot((upper_quantile,upper_quantile),(height-0.02,height+0.02),'r-',linewidth=2) if central == 'mean': (mu,mu_err,sigma,sigma_err) = distribution_values(data,weightdata,central) if plotting: gfunc = norm y = gfunc.pdf( bins, mu, sigma) plt.plot((mu,mu),(0,gfunc.pdf(mu,mu,sigma)),'r--',linewidth=2) l = plt.plot(bins, y, 'r--', linewidth=2) if central == 'trimmed': (mu,mu_err,sigma,sigma_err,lower,upper) = distribution_values(data,weightdata,central) if plotting: #print mu,sigma,ptbin gfunc = norm y = gfunc.pdf(bins, mu, sigma) plt.plot((mu,mu),(0,gfunc.pdf(mu,mu,sigma)),'r--',linewidth=2) newbins = bins[all([bins>lower,bins<upper],axis=0)] newy = y[all([bins>lower,bins<upper],axis=0)] l = plt.plot(newbins, newy, 'r--', linewidth=2) if plotting: plt.xlabel('$p_T^{reco}/p_T^{true}$') plt.ylabel('a.u.') plt.savefig(plotDir+'/'+'histfit_'+central+'.png') plt.close() #avgres.append(mu) #avgres_errs.append(mu_err) #sigmaRs.append(sigma) #sigmaR_errs.append(sigma_err) return mu,mu_err,sigma,sigma_err
import rootpy rootpy.log.basic_config_colorized() from rootpy.plotting import Canvas, Hist from rootpy.plotting.style import get_style from rootpy.interactive import wait try: kwargs = {} for arg in extra: name, value = arg.lstrip('--').split('=') kwargs[name] = value except ValueError: sys.exit("specify style parameters with --name=value") try: style = get_style(args.style, **kwargs) except ValueError: print('Invalid style: `{0}`. Using the `ATLAS` style.'.format(args.style)) style = get_style('ATLAS') # Use styles as context managers. The selected style will only apply # within the following context: with style: c = Canvas() hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") # generate some random data ROOT.gRandom.SetSeed() for i in xrange(25000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
help='Enable batch mode for ROOT.', ) # parse the arguments, throw errors if missing any args = parser.parse_args() import ROOT ROOT.PyConfig.IgnoreCommandLineOptions = True ROOT.gROOT.SetBatch(args.batch_mode) import numpy as np from rootpy.plotting.style import set_style, get_style atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) summary = json.load(file(args.summary)) plot_array = { 'sig': [r['significance'] for r in summary], 'signal': [r['signal'] for r in summary], 'bkgd': [r['bkgd'] for r in summary], 'mgluino': [r['m_gluino'] for r in summary], 'mlsp': [r['m_lsp'] for r in summary], 'ratio': [r['ratio'] for r in summary], } # load in supercuts
h1.linecolor = 'green' h1.linewidth = 0 h2.fillstyle = 'solid' h2.fillcolor = 'red' h2.linecolor = 'red' h2.linewidth = 0 stack = HistStack() stack.Add(h1) stack.Add(h2) # hack to change y-axis range in ROOT stack.SetMaximum(stack.GetMaximum() * 1.2) # plot with ROOT style = get_style('ATLAS') style.SetEndErrorSize(3) set_style(style) canvas = Canvas(width=700, height=500) stack.Draw('HIST E1 X0') h3.Draw('SAME E1 X0') stack.xaxis.SetTitle('Mass') stack.yaxis.SetTitle('Events') # set the number of expected legend entries legend = Legend(3, leftmargin=0.45, margin=0.3) legend.AddEntry(h1, style='F') legend.AddEntry(h2, style='F') legend.AddEntry(h3, style='LEP') legend.Draw() label = ROOT.TText(0.3, 0.8, 'ROOT') label.SetTextFont(43)
import ROOT from rootpy.plotting import Canvas, Hist from rootpy.plotting.style import get_style from rootpy.interactive import wait from rootpy.extern.six.moves import range try: kwargs = {} for arg in extra: name, value = arg.lstrip('--').split('=') kwargs[name] = value except ValueError: print("specify style parameters with --name=value") try: style = get_style(args.style, **kwargs) except ValueError: print('Invalid style: `{0}`. Using the `ATLAS` style.'.format(args.style)) style = get_style('ATLAS') # Use styles as context managers. The selected style will only apply # within the following context: with style: c = Canvas() hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") # generate some random data ROOT.gRandom.SetSeed() for i in range(25000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]")
def __enter__(self): """Override the __enter__ method to remember the current gStyle. """ self.old_gStyle = get_style(ROOT.gStyle.name) set_style(self) return self
Setting the plotting style ========================== This example demonstrates how to set the plotting style. """ print __doc__ import ROOT import rootpy rootpy.log.basic_config_colorized() from rootpy.plotting import Hist from rootpy.plotting.style import get_style from rootpy.interactive import wait atlas_style = get_style("ATLAS") # Use styles as context managers. The ATLAS style will only apply # within the following context: with atlas_style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") # generate some random data ROOT.gRandom.SetSeed() for i in xrange(25000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(1000.0) hpx.Draw() wait()
import rootpy rootpy.log.basic_config_colorized() from rootpy.plotting import Hist from rootpy.plotting.style import get_style from rootpy.interactive import wait try: style_name = sys.argv[1] except IndexError: print('Specify the style with the style name as an argument') print('Using the ATLAS style') style_name = 'ATLAS' try: style = get_style(style_name) except ValueError: print('Invalid style: `{}`. Using the `ATLAS` style.'.format(style_name)) style = get_style('ATLAS') # Use styles as context managers. The ATLAS style will only apply # within the following context: with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") # generate some random data ROOT.gRandom.SetSeed() for i in xrange(25000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(1000.)
if not os.path.exists(dir): mkdir_p(dir) return dir import numpy as np # for reproducibilty # especially for test/train set selection np.random.seed(1987) # my birth year ;) MMC_VERSION = 1 MMC_MASS = 'mmc%d_mass' % MMC_VERSION MMC_PT = 'mmc%d_resonance_pt' % MMC_VERSION from rootpy.plotting.style import get_style, set_style style = get_style('ATLAS', shape='square') #style.SetFrameLineWidth(2) #style.SetLineWidth(2) #style.SetTitleYOffset(1.8) #style.SetTickLength(0.04, 'X') #style.SetTickLength(0.02, 'Y') # custom HSG4 modifications style.SetPadLeftMargin(0.16) style.SetTitleYOffset(1.6) style.SetHistTopMargin(0.) style.SetHatchesLineWidth(1) style.SetHatchesSpacing(1) set_style(style)
import ROOT import rootpy rootpy.log.basic_config_colorized() from rootpy.plotting import Hist from rootpy.plotting.style import get_style from rootpy.interactive import wait try: style_name = sys.argv[1] except IndexError: print('Specify the style with the style name as an argument') print('Using the ATLAS style') style_name = 'ATLAS' try: style = get_style(style_name) except ValueError: print('Invalid style: `{}`. Using the `ATLAS` style.'.format(style_name)) style = get_style('ATLAS') # Use styles as context managers. The ATLAS style will only apply # within the following context: with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") # generate some random data ROOT.gRandom.SetSeed() for i in xrange(25000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(1000.)
#!/bin/env python2 import optparse,csv,sys sys.argv.append("-b") from ROOT import * import rootpy as rpy from rootpy.plotting.style import set_style, get_style import os atlas = get_style('ATLAS') atlas.SetPalette(51) set_style(atlas) sys.argv = sys.argv[:-1] topmass = 173.34 def parse_argv(): parser = optparse.OptionParser() parser.add_option("--lumi", help="luminosity", default=5, type=int) #parser.add_option("--z-label", help="z axis title", default="significance in optimal cut") parser.add_option("--text-file", help="text csv file", default=None, type=str) parser.add_option("--outdir", help="outfile directory", default="plots") parser.add_option("--outfilebase", help="outfile base name", default="output") parser.add_option("--g-min", help="min gluino mass", default=800, type=float) parser.add_option("--g-max", help="max gluino mass", default=2000, type=float) parser.add_option("--l-min", help="min lsp mass", default=0, type=float) parser.add_option("--l-max", help="max lsp mass", default=1300, type=float) parser.add_option("--bin-width", help="bin width", default=100, type=float) parser.add_option("--x-dim", help="x dimension of figure", default=800, type=float) parser.add_option("--y-dim", help="y dimension of figure", default=600, type=float)
def test_get_style(): mystyle = TStyle("mystyle", "some style") assert isinstance(get_style("mystyle"), Style)
import os.path, sys from rootpy.plotting import F1, Hist, Hist2D, HistStack, Canvas, Legend, Pad from rootpy.plotting.utils import draw #from rootpy.interactive import wait from rootpy.io import root_open from rootpy.tree import Cut from rootpy.plotting.style import get_style, set_style from decimal import Decimal import ROOT ROOT.gROOT.SetBatch(True) style = get_style('ATLAS') style.SetEndErrorSize(3) titlesize = 25 style.SetTitleSize(titlesize, "x") style.SetTitleSize(titlesize, "y") style.SetTitleYOffset(1) #style.SetTitleXOffset(3) #style.SetPadTopMargin(0.0) #style.SetPadRightMargin(0.05) #style.SetPadBottomMargin(0.2) #style.SetPadLeftMargin(0.15) #style.setPalette(51,0) set_style(style) labelmargin = 0.18 #Labeling #==================== EDIT THESE ========================# lumipb = 12300 #pb-1 (10 fb-1) lumifb = lumipb / 1000.0 sqrts = 13
This example demonstrates how to set the plotting style. """ print __doc__ import sys import ROOT import rootpy rootpy.log.basic_config_colorized() from rootpy.plotting import Hist from rootpy.plotting.style import get_style from rootpy.interactive import wait if len(sys.argv) == 1: print "you can also specify a style as argument" style = get_style(sys.argv[1] if len(sys.argv) > 1 else 'ATLAS') # Use styles as context managers. The ATLAS style will only apply # within the following context: with style: hpx = Hist(100, -4, 4, name="hpx", title="This is the px distribution") # generate some random data ROOT.gRandom.SetSeed() for i in xrange(25000): hpx.Fill(ROOT.gRandom.Gaus()) hpx.GetXaxis().SetTitle("random variable [unit]") hpx.GetYaxis().SetTitle("#frac{dN}{dr} [unit^{-1}]") hpx.SetMaximum(1000.) hpx.Draw() wait()