Hello,
Is there a better way to change the title of a canvas without changing the title of the underlying histogram?
I am trying to draw two histograms in the following manner
import ROOT
# Some data
rdf = ROOT.RDataFrame(10)
rdf = rdf.Define("x", "rdfentry_")
rdf = rdf.Define("y", "x*x")
# Making Histograms
hmodel = ROOT.RDF.TH1DModel("hx", "hx", 10, -0.5, 10.5)
hx = rdf.Histo1D(hmodel, "x")
hx.SetTitle("x")
hmodel = ROOT.RDF.TH1DModel("hy", "hy", 10, -0.5, 10.5)
hy = rdf.Histo1D(hmodel, "y")
hy.SetTitle("y")
hy.Scale(1.5)
hy.SetLineColor(ROOT.kRed)
# Drawing Histograms
c = ROOT.TCanvas()
ROOT.gStyle.SetOptStat(0)
hy.Draw("same")
hx.Draw("same")
c.BuildLegend()
c.Draw()
The output is the following, where I understand the first histogram is setting the output. I don’t want to change the histogram titles since they also affect the Legend.
The only work arounf I found to change the title was
def change_title(canvas, name):
old_title = canvas.FindObject("title")
title = ROOT.TPaveText(old_title.GetX1(), old_title.GetY1(), old_title.GetX2(), old_title.GetY2(), "title")
# old_title.Delete() # Does not always work for some reason
title.AddText(name)
title.Draw()
canvas.Update()
return title
The above is problematic for reasons related to the size of the text object and drawing of the canvas when in a notebook-like environment. Are there any other ways to change the title of the canvas?
Please read tips for efficient and successful posting and posting code
Please fill also the fields below. Note that root -b -q
will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug
from the ROOT prompt to pre-populate a topic.
ROOT Version: 6.35.001
Platform: CentOS7?
Compiler: linuxx8664gcc