Skip to content

Commit

Permalink
Use strings for colors in Python tutorials
Browse files Browse the repository at this point in the history
This makes the code less verbose and more pythonic.
  • Loading branch information
guitargeek committed Nov 25, 2024
1 parent 27a3769 commit 6010d29
Show file tree
Hide file tree
Showing 45 changed files with 97 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class RooAbsRealPlotOn(unittest.TestCase):
def test_frame(self):
# test that kwargs can be passed
# and lead to correct result
r1 = self.gauss.plotOn(self.xframe, ROOT.RooFit.LineColor(ROOT.kRed))
r2 = self.gauss.plotOn(self.xframe, LineColor=ROOT.kRed)
r1 = self.gauss.plotOn(self.xframe, LineColor="r")
r2 = self.gauss.plotOn(self.xframe, LineColor="r")

def test_wrong_kwargs(self):
# test that AttributeError is raised
Expand Down
2 changes: 1 addition & 1 deletion tree/dataframe/src/RDataFrame.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ You can also include a global callback function that will be applied to all plot
~~~{.py}
def set_fill_color(hist):
hist.SetFillColor(ROOT.kBlue)
hist.SetFillColor("kBlue")
LiveVisualize([h_gaus, h_exp, h_random], set_fill_color)
~~~
Expand Down
10 changes: 5 additions & 5 deletions tutorials/dataframe/df103_NanoAODHiggsAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@ def plot(sig, bkg, data, x_label, filename):
h_cmb.GetXaxis().SetTitleSize(0.04)
h_cmb.GetYaxis().SetTitle("N_{Events}")
h_cmb.GetYaxis().SetTitleSize(0.04)
h_cmb.SetLineColor(ROOT.kRed)
h_cmb.SetLineColor("kRed")
h_cmb.SetLineWidth(2)
h_cmb.SetMaximum(18)
h_cmb.SetStats(False)

h_bkg.SetLineWidth(2)
h_bkg.SetFillStyle(1001)
h_bkg.SetLineColor(ROOT.kBlack)
h_bkg.SetFillColor(ROOT.kAzure - 9)
h_bkg.SetLineColor("kBlack")
h_bkg.SetFillColor("kAzure - 9")

# Get histogram of data points
h_data = data.Clone()
h_data.SetLineWidth(1)
h_data.SetMarkerStyle(20)
h_data.SetMarkerSize(1.0)
h_data.SetMarkerColor(ROOT.kBlack)
h_data.SetLineColor(ROOT.kBlack)
h_data.SetMarkerColor("kBlack")
h_data.SetLineColor("kBlack")

# Draw histograms
h_cmb.Draw("HIST")
Expand Down
2 changes: 1 addition & 1 deletion tutorials/dataframe/df104_HiggsToTwoPhotons.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
data.SetMarkerStyle(20)
data.SetMarkerSize(1.2)
data.SetLineWidth(2)
data.SetLineColor(ROOT.kBlack)
data.SetLineColor("kBlack")
data.SetMinimum(1e-3)
data.SetMaximum(8e3)
data.GetYaxis().SetLabelSize(0.045)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/dataframe/df105_WBosonAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def merge_histos(label):
data.SetMarkerStyle(20)
data.SetMarkerSize(1.2)
data.SetLineWidth(2)
data.SetLineColor(ROOT.kBlack)
data.SetLineColor("kBlack")
data.Draw("E SAME")

# Add legend
Expand Down
10 changes: 5 additions & 5 deletions tutorials/dataframe/df106_HiggsToFourLeptons.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class VaryHelper
h_zz = histos[2].GetValue().Clone()
h_other = histos[3].GetValue().Clone()

for h, color in zip([h_other, h_zz, h_higgs], [ROOT.kViolet - 9, ROOT.kAzure - 9, ROOT.kRed + 2]):
for h, color in zip([h_other, h_zz, h_higgs], ["kViolet - 9", "kAzure - 9", "kRed + 2"]):
h.SetLineWidth(1)
h.SetLineColor(1)
h.SetFillColor(color)
Expand All @@ -250,19 +250,19 @@ class VaryHelper
stack.GetYaxis().ChangeLabel(1, -1, 0)

# Draw MC scale factor and variations
histos_mc["nominal"].SetFillColor(ROOT.kBlack)
histos_mc["nominal"].SetFillColor("kBlack")
histos_mc["nominal"].SetFillStyle(3254)
h_nominal = histos_mc["nominal"].DrawClone("E2 same")
histos_mc["weight:up"].SetLineColor(ROOT.kGreen + 2)
histos_mc["weight:up"].SetLineColor("kGreen + 2")
h_weight_up = histos_mc["weight:up"].DrawClone("HIST SAME")
histos_mc["weight:down"].SetLineColor(ROOT.kBlue + 2)
histos_mc["weight:down"].SetLineColor("kBlue + 2")
h_weight_down = histos_mc["weight:down"].DrawClone("HIST SAME")

# Draw data histogram
h_data.SetMarkerStyle(20)
h_data.SetMarkerSize(1.2)
h_data.SetLineWidth(2)
h_data.SetLineColor(ROOT.kBlack)
h_data.SetLineColor("kBlack")
h_data.Draw("E SAME") # Draw raw data with errorbars

# Add legend
Expand Down
2 changes: 1 addition & 1 deletion tutorials/dataframe/df107_SingleTopAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def merge_histos(label):
data.SetMarkerStyle(20)
data.SetMarkerSize(1.2)
data.SetLineWidth(2)
data.SetLineColor(ROOT.kBlack)
data.SetLineColor("kBlack")
data.Draw("E SAME")

# Add legend
Expand Down
4 changes: 2 additions & 2 deletions tutorials/fit/combinedFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ def __call__(self, par):

fB.SetFitResult(result, iparB)
fB.SetRange(rangeB().first, rangeB().second)
fB.SetLineColor(ROOT.kBlue)
fB.SetLineColor("kBlue")
hB.GetListOfFunctions().Add(fB)
hB.Draw()

c1.cd(2)
fSB.SetFitResult(result, iparSB)
fSB.SetRange(rangeSB().first, rangeSB().second)
fSB.SetLineColor(ROOT.kRed)
fSB.SetLineColor("kRed")
hSB.GetListOfFunctions().Add(fSB)
hSB.Draw()

Expand Down
2 changes: 1 addition & 1 deletion tutorials/graphs/timeSeriesFromCSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
c.SetRightMargin(0.04)
c.SetGrid()
g.SetLineWidth(3)
g.SetLineColor(ROOT.kBlue)
g.SetLineColor("kBlue")
g.Draw("al")
g.GetYaxis().CenterTitle()

Expand Down
6 changes: 3 additions & 3 deletions tutorials/hist/twoscales.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

rightmax = 1.1*hint1.GetMaximum()
scale = ROOT.gPad.GetUymax()/rightmax
hint1.SetLineColor(ROOT.kRed)
hint1.SetLineColor("kRed")
hint1.Scale(scale)
hint1.Draw("same")

axis = ROOT.TGaxis(ROOT.gPad.GetUxmax(),ROOT.gPad.GetUymin(),
ROOT.gPad.GetUxmax(), ROOT.gPad.GetUymax(),0,rightmax,510,"+L")
axis.SetLineColor(ROOT.kRed)
axis.SetLabelColor(ROOT.kRed)
axis.SetLineColor("kRed")
axis.SetLabelColor("kRed")
axis.Draw()
6 changes: 3 additions & 3 deletions tutorials/histfactory/hf001_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
xmax = poi.getMax()

line = ROOT.TLine(xmin, 0.5, xmax, 0.5)
line.SetLineColor(ROOT.kGreen)
line.SetLineColor("kGreen")
line90 = ROOT.TLine(xmin, 2.71 / 2, xmax, 2.71 / 2)
line90.SetLineColor(ROOT.kGreen)
line90.SetLineColor("kGreen")
line95 = ROOT.TLine(xmin, 3.84 / 2, xmax, 3.84 / 2)
line95.SetLineColor(ROOT.kGreen)
line95.SetLineColor("kGreen")

frame.addObject(line)
frame.addObject(line90)
Expand Down
6 changes: 3 additions & 3 deletions tutorials/pyroot/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
cons.SetLineColor( 3 )
pcon.SetLineColor( 6 )
pgon.SetLineColor( 2 )
sphe.SetLineColor( ROOT.kRed )
sphe1.SetLineColor( ROOT.kBlack )
sphe2.SetLineColor( ROOT.kBlue )
sphe.SetLineColor("kRed")
sphe1.SetLineColor("kBlack")
sphe2.SetLineColor("kBlue")

# Build the geometry hierarchy
node1 = ROOT.TNode( 'NODE1', 'NODE1', 'BRIK' )
Expand Down
8 changes: 4 additions & 4 deletions tutorials/pyroot/zdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def zdemo():
t.DrawLatex( 0.18, 0.40, '(barn/Gev^{2})' )

t.SetTextSize( 0.045 )
t.SetTextColor( ROOT.kBlue )
t.SetTextColor("kBlue")
t.DrawLatex( 0.22, 0.260, '#sqrt{s} = 63(GeV)' )
t.SetTextColor( ROOT.kRed )
t.SetTextColor("kRed")
t.DrawLatex( 0.22, 0.205,'#sqrt{s} = 200(GeV)' )
t.SetTextColor( 6 )
t.DrawLatex( 0.22, 0.15, '#sqrt{s} = 500(GeV)' )
Expand Down Expand Up @@ -210,7 +210,7 @@ def zdemo():

gr2 = ROOT.TGraph( NLOOP, PT, INVSIG )
gr2.SetLineColor( 38 )
gr2.SetMarkerColor( ROOT.kRed )
gr2.SetMarkerColor("kRed")
gr2.SetMarkerStyle( 29 )
gr2.SetMarkerSize( 1.5 )
gr2.Draw( 'LP' )
Expand Down Expand Up @@ -246,7 +246,7 @@ def zdemo():
saves[ 'graph' ] = graph

graph = ROOT.TGraph( 1, dum, dum )
graph.SetMarkerColor( ROOT.kRed )
graph.SetMarkerColor("Red")
graph.SetMarkerStyle( 29 )
graph.SetMarkerSize( 1.5 )
graph.SetPoint( 0, 1.7, 2.e-17 )
Expand Down
2 changes: 1 addition & 1 deletion tutorials/rcanvas/df104.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
data.SetMarkerStyle(20)
data.SetMarkerSize(1.2)
data.SetLineWidth(2)
data.SetLineColor(ROOT.kBlack)
data.SetLineColor("kBlack")
data.SetMinimum(1e-3)
data.SetMaximum(8e3)
data.GetYaxis().SetLabelSize(0.045)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/rcanvas/df105.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def merge_histos(label):
data.SetMarkerStyle(20)
data.SetMarkerSize(1.2)
data.SetLineWidth(2)
data.SetLineColor(ROOT.kBlack)
data.SetLineColor("kBlack")
c.Add[TObjectDrawable]().Set(data, "E SAME")

# Add TLegend while histograms packed in the THStack
Expand Down
6 changes: 3 additions & 3 deletions tutorials/roofit/rf106_plotdecoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
# Add text to frame
txt = ROOT.TText(2, 100, "Signal")
txt.SetTextSize(0.04)
txt.SetTextColor(ROOT.kRed)
txt.SetTextColor("kRed")
frame.addObject(txt)

# Add arrow to frame
arrow = ROOT.TArrow(2, 100, -1, 50, 0.01, "|>")
arrow.SetLineColor(ROOT.kRed)
arrow.SetFillColor(ROOT.kRed)
arrow.SetLineColor("kRed")
arrow.SetFillColor("kRed")
arrow.SetLineWidth(3)
frame.addObject(arrow)

Expand Down
2 changes: 1 addition & 1 deletion tutorials/roofit/rf211_paramconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
ConditionalObservables={mean},
)
hh.SetTitle("histogram of model(x|mean)")
hh.SetLineColor(ROOT.kBlue)
hh.SetLineColor("kBlue")

# Draw frame on canvas
c = ROOT.TCanvas("rf211_paramconv", "rf211_paramconv", 800, 400)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/roofit/rf301_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

# Make two-dimensional plot in x vs y
hh_model = model.createHistogram("hh_model", x, Binning=50, YVar=dict(var=y, Binning=50))
hh_model.SetLineColor(ROOT.kBlue)
hh_model.SetLineColor("kBlue")

# Make canvas and draw ROOT.RooPlots
c = ROOT.TCanvas("rf301_composition", "rf301_composition", 1200, 400)
Expand Down
8 changes: 4 additions & 4 deletions tutorials/roofit/rf302_utilfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
hh_model_2 = model_2.createHistogram("hh_model_2", x, Binning=50, YVar=dict(var=y, Binning=50))
hh_model_3 = model_3.createHistogram("hh_model_3", x, Binning=50, YVar=dict(var=y, Binning=50))
hh_model_4 = model_4.createHistogram("hh_model_4", x, Binning=50, YVar=dict(var=y, Binning=50))
hh_model_1.SetLineColor(ROOT.kBlue)
hh_model_2.SetLineColor(ROOT.kBlue)
hh_model_3.SetLineColor(ROOT.kBlue)
hh_model_4.SetLineColor(ROOT.kBlue)
hh_model_1.SetLineColor("kBlue")
hh_model_2.SetLineColor("kBlue")
hh_model_3.SetLineColor("kBlue")
hh_model_4.SetLineColor("kBlue")

# Make canvas and draw ROOT.RooPlots
c = ROOT.TCanvas("rf302_utilfuncs", "rf302_utilfuncs", 800, 800)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/roofit/rf305_condcorrprod.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

# Make two-dimensional plot in x vs y
hh_model = model.createHistogram("hh_model", x, ROOT.RooFit.Binning(50), ROOT.RooFit.YVar(y, ROOT.RooFit.Binning(50)))
hh_model.SetLineColor(ROOT.kBlue)
hh_model.SetLineColor("kBlue")

# Make canvas and draw ROOT.RooPlots
c = ROOT.TCanvas("rf305_condcorrprod", "rf05_condcorrprod", 1200, 400)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/roofit/rf306_condpereventerrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

# Make two-dimensional plot of conditional pdf in (dt,dterr)
hh_decay = decay_gm.createHistogram("hh_decay", dt, Binning=50, YVar=dict(var=dterr, Binning=50))
hh_decay.SetLineColor(ROOT.kBlue)
hh_decay.SetLineColor("kBlue")

# Plot decay_gm(dt|dterr) at various values of dterr
frame = dt.frame(Title="Slices of decay(dt|dterr) at various dterr")
Expand Down
2 changes: 1 addition & 1 deletion tutorials/roofit/rf307_fullpereventerrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

# Make two-dimensional plot of conditional pdf in (dt,dterr)
hh_model = model.createHistogram("hh_model", dt, Binning=50, YVar=dict(var=dterr, Binning=50))
hh_model.SetLineColor(ROOT.kBlue)
hh_model.SetLineColor("kBlue")

# Make projection of data an dt
frame = dt.frame(Title="Projection of model(dt|dterr) on dt")
Expand Down
2 changes: 1 addition & 1 deletion tutorials/roofit/rf308_normintegration2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

# Plot cdf of gx versus x
hh_cdf = gxy_cdf.createHistogram("hh_cdf", x, Binning=40, YVar=dict(var=y, Binning=40))
hh_cdf.SetLineColor(ROOT.kBlue)
hh_cdf.SetLineColor("kBlue")

c = ROOT.TCanvas("rf308_normintegration2d", "rf308_normintegration2d", 600, 600)
ROOT.gPad.SetLeftMargin(0.15)
Expand Down
4 changes: 2 additions & 2 deletions tutorials/roofit/rf309_ndimplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# Create and fill ROOT 2D histogram (50x50 bins) with sampling of pdf
# hh_pdf = model.createHistogram("hh_model", x, Binning=50, YVar=dict(var=y, Binning=50))
hh_pdf = model.createHistogram("x,y", 50, 50)
hh_pdf.SetLineColor(ROOT.kBlue)
hh_pdf.SetLineColor("kBlue")

# Create 3D model and dataset
# -----------------------------------------------------
Expand Down Expand Up @@ -76,7 +76,7 @@
YVar=dict(var=y, Binning=20),
ZVar=dict(var=z, Binning=20),
)
hh_pdf3.SetFillColor(ROOT.kBlue)
hh_pdf3.SetFillColor("kBlue")

c1 = ROOT.TCanvas("rf309_2dimplot", "rf309_2dimplot", 800, 800)
c1.Divide(2, 2)
Expand Down
2 changes: 1 addition & 1 deletion tutorials/roofit/rf315_projectpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

# Make 2D histogram of model(x,y)
hh = model.createHistogram("x,y")
hh.SetLineColor(ROOT.kBlue)
hh.SetLineColor("kBlue")

c = ROOT.TCanvas("rf315_projectpdf", "rf315_projectpdf", 800, 400)
c.Divide(2)
Expand Down
8 changes: 4 additions & 4 deletions tutorials/roofit/rf608_fitresultaspdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# Sample a 3-D histogram of the pdf to be visualized as an error
# ellipsoid using the GLISO draw option
hh_3d = parabPdf.createHistogram("mean,sigma_g2,frac", 25, 25, 25)
hh_3d.SetFillColor(ROOT.kBlue)
hh_3d.SetFillColor("kBlue")

# Project 3D parameter pdf down to 3 permutations of two-dimensional pdfs
# The integrations corresponding to these projections are performed analytically
Expand All @@ -66,9 +66,9 @@
hh_sigmag2_frac = pdf_sigmag2_frac.createHistogram("sigma_g2,frac", 50, 50)
hh_mean_frac = pdf_mean_frac.createHistogram("mean,frac", 50, 50)
hh_mean_sigmag2 = pdf_mean_sigmag2.createHistogram("mean,sigma_g2", 50, 50)
hh_mean_frac.SetLineColor(ROOT.kBlue)
hh_sigmag2_frac.SetLineColor(ROOT.kBlue)
hh_mean_sigmag2.SetLineColor(ROOT.kBlue)
hh_mean_frac.SetLineColor("kBlue")
hh_sigmag2_frac.SetLineColor("kBlue")
hh_mean_sigmag2.SetLineColor("kBlue")

# Draw the 'sigar'
ROOT.gStyle.SetCanvasPreferGL(True)
Expand Down
8 changes: 4 additions & 4 deletions tutorials/roofit/rf615_simulation_based_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def learned_likelihood_ratio(x, mu):
frame1.Draw()

legend1 = ROOT.TLegend(0.43, 0.63, 0.8, 0.87)
legend1.SetFillColor(ROOT.kWhite)
legend1.SetLineColor(ROOT.kWhite)
legend1.SetFillColor("kWhite")
legend1.SetLineColor("kWhite")
legend1.SetTextSize(0.04)
legend1.AddEntry("learned", "learned (SBI)", "L")
legend1.AddEntry("gauss", "true NLL", "L")
Expand All @@ -247,8 +247,8 @@ def learned_likelihood_ratio(x, mu):
frame2.Draw()

legend2 = ROOT.TLegend(0.53, 0.73, 0.87, 0.87)
legend2.SetFillColor(ROOT.kWhite)
legend2.SetLineColor(ROOT.kWhite)
legend2.SetFillColor("kWhite")
legend2.SetLineColor("kWhite")
legend2.SetTextSize(0.04)
legend2.AddEntry("learned_ratio", "learned (SBI)", "L")
legend2.AddEntry("exact", "true ratio", "L")
Expand Down
Loading

0 comments on commit 6010d29

Please sign in to comment.