Large caption on histogram

Dear reader,

I would like to make a very large title on my histogram such that it can be well read. But I do not seem to succeed. I have tried the methods SetTitleSize, but I see no effect (I call this before drawing).

With the mouse on the canvas, I right click on the title, and I see that is an TPaveText object. But I cannot locate this object as member of the TH1F (or one of the parent objects).

With the mouse I can easily resize the title (pave). Which methods are called there? How could I set those myself in a batch job?

Kind regards,

Ytsen.

Hello Ytsen,

You could save the source of your histogram as *.C file and have a look
how the title is generated. For example:

TPaveText *pt = new TPaveText(0.01,0.945,0.684118,0.995,"blNDC");
pt->SetName("title");
pt->SetBorderSize(2);
pt->SetFillColor(19);
text = pt->AddText("Summ of all invariant mass differences");
pt->Draw();

So you can see that you should get the object “title” after the drawing
and change its properties.

           virtual void SetX1NDC(Double_t x1)
           virtual void SetX2NDC(Double_t x2)
           virtual void SetY1NDC(Double_t y1)
           virtual void SetY2NDC(Double_t y2)

        virtual void SetTextAlign(Short_t align = 11)
         virtual void SetTextAngle(Float_t tangle = 0)
         virtual void SetTextAttributes()
         virtual void SetTextColor(Color_t tcolor = 1)
         virtual void SetTextFont(Font_t tfont = 62)
         virtual void SetTextSize(Float_t tsize = 1)

8)

As indicated by Sergei, you can generate the code corresponding to what you have in the canvas.

Note that you can change interactively the size of the box title with the mouse.
If you want to change teh default title box size, see the class TStyle
void SetTitleX(Float_t x=0) {fTitleX=x;}
void SetTitleY(Float_t y=0.985) {fTitleY=y;}
void SetTitleW(Float_t w=0) {fTitleW=w;}
void SetTitleH(Float_t h=0) {fTitleH=h;}

Rene

Dear Sergei and Rene,

Thanks for the replies, but unfortunately they are too complicated or expertive because I don’t understand.

Sergei, when I look at the code of TH1(F) or one of the parent classes, I do not find the creation of a TPaveText that subsequently is added as title box to the histogram. Trying to trace it through the TH1::Draw() method but I get wound up in gPads and TPainters?

Neither am I able to get the object “title” through the memberfunction FindObject() of TNamed. With the mouse I find out that the name of the TPaveObject::title is `title’. Then I type in CINT: h1->GetObject(“title”), which returns a 0x0 pointer (h1 is a TH1F). So this is not the way neither.

The GetTitle() returns the name only, the SetTitleSize() has no effect at all(?), before or after drawing. I wouldn’t know how to retrieve the title box otherwise, let alone how to add it again when modified to my needs.

Rene, I see the methods you mention in the TStyle class. But so long as I do not have an object of this type I cannot change it, and, as said, add it again as the title box.

Well, I hope you see what I do not see and I hope it is simple.

Best,

Ytsen. :unamused:

To access the title object in the pad, do
TPaveText title = (TPaveText)gPad->GetPrimitive(“title”);

Concerning the TStyle, you can use the default TStyle pointed by gStyle.
gStyle->SetTitleW(0.7);

See examples in tutorials and Users Guide.

Rene

Hello,

Well, just to let you know the score on this one: I can draw a TPaveText and just put it over the original title box and that will do. Directly trying to manipulate the title box has resulted in nothing but seg faults.

Thanks for the tips.

Cheers,

Ytsen.

Hello again, I reposted the problem, maybe you could try again again? I must be doing something very wrong.

Regards,

Ytsen.

I am afraid that we are running into circles.
Please send a 10 lines long script showing your problem.

Rene

Hello again,

I post the lines below that produce the attached plot. It is not the minimum code but I wanted to stick as close as possible to my own code.

{

gROOT->Reset();

Double_t xaxis[20], yaxis[20];

for (Int_t i = 0; i<20; ++i){ xaxis[i] = 4. * i; yaxis[i] = 60./(2.+i); }

TGraph * RawLumiGraph = new TGraph(20, xaxis, yaxis);

TCanvas * lastUpdateCanv = new TCanvas(“lastUpdate”,“lastUpdate”,0,0, 600,600);

TH2F axFill(“axFill”,“TH2 title”, 10, 0, 20, 10, 0, 50);
axFill.SetStats(kFALSE);
axFill.GetXaxis()->SetTitle(“X-axis”);
axFill.GetYaxis()->SetTitle(“Y-axis”);

axFill->Draw();
RawLumiGraph->Draw(“B”);

// Now adding the `new’ title
TPaveText * tpt = new TPaveText(0,50, 20,55);
TText * t1 = tpt->AddText(“The new title”);
tpt->Draw();

}

You see that the `old’ title is still there, how would I remove it?

Regards,

Ytsen.


Hi Ytsen,

try this at the begining of your code:

gStyle->SetTitleX(0.1f);
gStyle->SetTitleW(0.8f);
gStyle->SetTitleY(0.98f);

and play with values to fit your wishes.
HTH.

Cheers,
Bertrand.

To be more precise :wink: :

{

gROOT->Reset();
gStyle->SetTitleX(0.1f);
gStyle->SetTitleW(0.8f);
gStyle->SetTitleY(0.98f);

Double_t xaxis[20], yaxis[20];

for (Int_t i = 0; i<20; ++i){ xaxis[i] = 4. * i; yaxis[i] = 60./(2.+i); }

TGraph * RawLumiGraph = new TGraph(20, xaxis, yaxis);

TCanvas * lastUpdateCanv = new TCanvas(“lastUpdate”,“lastUpdate”,0,0, 600,600);

TH2F axFill(“axFill”,“TH2 title”, 10, 0, 20, 10, 0, 50);
axFill.SetStats(kFALSE);
axFill.GetXaxis()->SetTitle(“X-axis”);
axFill.GetYaxis()->SetTitle(“Y-axis”);

axFill->Draw();
RawLumiGraph->Draw(“B”);

}

Bertrand.


Well, thanks, this works great!

But now I get seg faults:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 18887)]
0x43ea210f in TH1::~TH1 () from /products/ROOT/3.10_03/gcc-2.95.3/root/lib/libHist.so

Do I have to delete anything that gStyle creates?

I make several histograms and only wrote once the gStyle commands.

Best,

Ytsen.

I don’t think the seg fault is related to gStyle…
gStyle only sets size and position of Histo title.

Bertrand.