Graphics Title issue


I would like to change the default title but keep the same style as the default one.
(position etc…) I used the following code.

void test() {

	TCanvas *c = new TCanvas("c1","c2");
        TPad *p = (TPad*) c;

        TH1D* h = new TH1D("test", "test title", 10, 0 ,1);

        TPaveText *pt = (TPaveText*)(p->GetPrimitive("title"));

        TPaveText* ptn = (TPaveText*) pt->Clone("txitle0");

        ptn->AddText("New TITLE0");



However when I move the window the new title disappear. My assumption is that when moving object are redrawn and as I set “gStyle->SetOptTitle(0)”. The pt doest not exists anymore, and ptn seems to be also deleted for some reason. Is this understanding correct ?

How should I handle this to avoid the title to disappear ?

Thank you !


h->SetTitle("New TITLE0;My X Axis;My Y Axis");
gPad->Modified(); gPad->Update();


I specially want to avoid it, because I want to detach the TPaveText from the histogram.
And possibly modify it later.

Do you have any idea why the TPaveText is diseapping and possibly how to fix it ?
Is this is due to the Clone function ?

If it is coming from the clone function.
I guess I could get the position NDC, but then the style is not the same :frowning:

@couet It seems to be a bug. The Clone method does not change the TPave name so, one needs to:


I am not sure I understand what you are doing. It seems you simply want to change the histogram title ? … why are you doing something that complicated ? The TPaveText is created when the histogram is drawn you cannot “detach” it … What is the use case of a such exercise ?

Hi, I use and reuse an histogram in multiple canvas as comparison reference.

It already happened for some reasons that the title is updating by itself due to graphics update and got confused by that. I prefer to have a dedicated title without any ambiguity and put the histogram title one for all instead of changing it as many times I need to draw a TPad.
Additionally, I also got confusions while drawing the legend.

So after getting the TPaveText I can just clone it as many time as I want and keep same position and style.

Btw, I think this title should not be a feature of the histogram/graph/etc…, but rather TVirtualPad.
However I understand it makes simpler when one is using h->Draw();

This I do not understand. The histogram title is fixed unless it is changed by SetTitle. Do you have some macro reproducing this uncontrolled title change ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.