Write a python macro ExerciseCanvas.py
.
hist2.FillRandom("pol2", 500)
).kRed
and second to kBlue
.(0.16, 0.63, 0.45, 0.91)
; bonus: do it after you created both canvases.import ROOT
%jsroot on
Welcome to JupyROOT 6.28/00
from ROOT import gStyle, TCanvas, TH1D, TLegend, kRed, kBlue
gStyle.SetOptStat(0)
canvas1 = TCanvas("canvas1", "", 800, 600)
hist1 = TH1D("hist1", "Gauss", 50, -3, 3)
hist2 = TH1D("hist2", "Polynomial", 50, -3, 3)
hist1.FillRandom("gaus", 10000)
hist2.FillRandom("pol2", 5000)
hist1.SetLineColor(kRed)
hist2.SetLineColor(kBlue)
hist1.Draw()
hist2.Draw("same")
canvas2 = TCanvas("canvas2", "", 800, 600)
hist1_norm = hist1.Clone("hist1_norm")
hist1_norm.Scale(1 / hist1.Integral())
hist2_norm = hist2.Clone("hist2_norm")
hist2_norm.Scale(1 / hist2.Integral())
hist1_norm.Draw("hist")
hist2_norm.Draw("hist same")
legend = TLegend(0.7, 0.75, 0.90, 0.87)
legend.AddEntry(hist1, hist1.GetTitle(), "l")
legend.AddEntry(hist2, hist2.GetTitle(), "l")
legend.SetBorderSize(0)
canvas1.cd()
legend.Draw()
canvas2.cd()
legend.Draw()
canvas1.Draw()
canvas2.Draw()
canvas1.SaveAs("output.pdf(")
canvas2.SaveAs("output.pdf)")
Info in <TCanvas::Print>: pdf file output.pdf has been created using the current canvas Info in <TCanvas::Print>: Current canvas added to pdf file output.pdf and file closed
Last update: 06 March 2023