Adding a value on an axis

Hi,

I drew multiple TH2 histograms in a divided TCanvas, which looks like this :

I have 3 little problems with it. I tried different things to solve them but nothing worked so far.

  1. My main problem is I want to add a specific value on the x-axis. Ideally, I’d want to add for example the number “34” on the x-axis (at the right place on the x axis) and written in red characters. I tried to play with the “bin” functions but nothing worked. Is there a simple way to do it ?

  2. I can’t change the size of the title for the TH2 histograms (“a” and “b” on the image). I used the SetTitleSize() method on the TH2 Histograms but it didn’t work. I also used the Update() method afterwards, just in case.

  3. I put a title on the TCanvas but it doesn’t appear. I also tried to put a top margin on TCanvas (with the SetTopMargin() method) but it didn’t work either.

Thanks for your help.

You should use TText to put this exact value at the right place. Drawing the text in the histogram coordinates (default) should put it automatically at the right place.

gStyle->SetTitleFontSize();

Send a small running macro reproducing this problem.

Exactly what I was looking for. Thank you !

Thank you again !

Send a small running macro reproducing this problem.[/quote]
Maybe the title of a TCanvas is not supposed to be seen but here is an example of a macro :

[code]{
TCanvas* canvas = new TCanvas(“Canvas”, “CanvasTitle”, 0, 0, 500, 500);

canvas->SetTopMargin(0.1);

canvas->Divide(1,2);
canvas->cd(1);

TH1F* hist1 = new TH1F(“Hist1”, “Title1”, 1, 0, 100);
hist1->SetFillColor(kGray);
for (int i = 0; i < 4; ++i) {
char dataName[50];
sprintf(dataName, “Data%d”, i);
hist1->Fill(dataName, 10 + 50*i);
}
hist1->Draw(“bar”);
} [/code]

I create a canvas, set a topMargin (of 10% if I understand correctly), then divide the Canvas, and draw a (non important) histogram in the first part of the canvas.
My problems with this are :

  • the title of the TCanvas is not displayed
  • the margin I tried to create for the Canvas is not created either

But again, maybe I’m trying to do something unintended.

Oh OK… I see what you mean now. No, the canvas title is not intended to be seen. It defines the tittle which appears on the window title bar. If you need a global title somehow, you should add an other TPaveText.

Ok I’ll do that. Thank you again !