Changing displayed title in canvas

I’m not quite sure what its called, but when you draw a histogram, its title appears in a box in the canvas. Is there any way to edit this text without changing the title of the histogram?

The reason I ask is that I’d like to put multiple histograms on the same TCanvas, and have a legend. The legend entries are generated by the titles of the TH1’s, and I don’t want the first legend entry to be the same as the tile displayed in the title box.


1 Like

Disable the title and add yourself your title with a TPaveLabel, eg

gStyle->SetOptTitle(0); TPaveLabel *title = new TPaveLabel(.11,.95,.35,.99,"my new title","brndc"); title->Draw();


This seems to work for me in cint, but not in a script I’ve written. In the script, the title appears squished to a line just under the x-axis. If I drag it, it pops up to full size. However, I’d like the script to make the title automatically, without my intervention.

The script loops through several trees, plotting the same histogram from each one. Is there something in this code that will prevent the title from printing properly. I should mention I’m using root 5.18.

 TCanvas * cnv = new TCanvas(histName+"_cnv",histName,800,570);

  bool isFirstHist = true;
  int nTrees = m_trees.size();
  for(int itr = 0; itr < nTrees; itr++)
    TString treeName = m_names[itr];
    TTree * tree = m_trees[itr];
    //Creating Histogram
    TString fullHistName = histName + " - " + treeName;
    TH1D * hist = new TH1D(fullHistName, treeName, nBins, lowBound, highBound);
    tree->Project(fullHistName, DrawCmd , treeConditions);
    if(ymin != ymax)
    isFirstHist = false;

  //Create legend
//  cnv->BuildLegend(.75,.85,.99,.99);

  //Create title
  TPaveLabel *title = new TPaveLabel(.11,.95,.70,.99,"my new title","brndc");


But how come can not delete it with right click and then select delete. I can delete any object but this.

Add cnv->Update(); after title->Draw();


Thanks, but that still didn’t fix it…

I tried right clicking on the flat label, and inspecting it. I got coordinates:
fX1 = 0.154352
fY1 = -13.6815
fX2 = 0.744167
fY1 = -13.6414

Which I guess is pretty much squished flat, and not what I entered.

Post the shortest possible RUNNING script showing the problem.