SubPad does not keep its SetPaintTextFormat unless

Hi,

Enclosed is a simple program that illustrate the issue in Root versions 5.26 and 5.30.

The program prints the number PI=3.1416 in four subpads. In each subpad, I set a different number of decimal places to print using the TH1->SetPaintTextFormat(".xf"), where x is the intended number of decimal places to print.
The histogram prints the correct number of decimal places in each subpad.
However, if one clicks any of the first three subpads with the midle mouse button, the text formatting will revert to the format issued in the last subpad, i.e, in this case, zero decimal place to print.

Two methods can be used to stop the formatting to revert to the last issued format:

  1. TH1->SetEditable(false)
  2. TH1->SetBit(kCannotPick)

I would think the observed behavior is a bug, since I would have the subpads to keep their intended formatting.

Vi-Hoa

In fact, I later found out that if you rezise the “mother” canvas, all the numbers in subpads will have the format issued in the last pad. So, it is definitely a bug

[code]{

TCanvas *c=new TCanvas(“FormatText”,“FormatText”,500,500);

c->Divide(2,2);

Float_t Pi=3.1416;
TH2D *hist=new TH2D(“one”,“one”,1,0.0,1.0, 1,0.0,1.0);
hist->SetBinContent(1,1,Pi);
hist->SetMarkerSize(3);

c->cd(1);
gStyle->SetPaintTextFormat(".3f");
hist->Draw(“TEXT”);
//gPad->SetBit(kcannotPick);
gPad->SetEditable(false);
gPad->Update();

c->cd(2);
gStyle->SetPaintTextFormat(".2f");
hist->Draw(“TEXT”);
gPad->Update();

c->cd(3);
gStyle->SetPaintTextFormat(".1f");
hist->Draw(“TEXT”);
gPad->Update();

c->cd(4);
gStyle->SetPaintTextFormat(".0f");
hist->Draw(“TEXT”);
gPad->Update();

}
[/code]
testSetPaintTextFormat.c (598 Bytes)

You should do:

{
   TCanvas *c=new TCanvas("FormatText","FormatText",500,500);

   c->Divide(2,2);

   Float_t Pi=3.1416;
   TH2D *hist=new TH2D("one","one",1,0.0,1.0, 1,0.0,1.0);
   hist->SetBinContent(1,1,Pi);
   hist->SetMarkerSize(3);

   c->cd(1); gPad->DrawFrame(0.,0.,1.,1.);
   TExec *ex1 = new TExec("ex1","gStyle->SetPaintTextFormat(\".3f\");");
   ex1->Draw();
   hist->Draw("TEXT SAME");


   c->cd(2); gPad->DrawFrame(0.,0.,1.,1.);
   TExec *ex2 = new TExec("ex2","gStyle->SetPaintTextFormat(\".2f\");");
   ex2->Draw();
   hist->Draw("TEXT SAME");

   c->cd(3); gPad->DrawFrame(0.,0.,1.,1.);
   TExec *ex3 = new TExec("ex3","gStyle->SetPaintTextFormat(\".1f\");");
   ex3->Draw();
   hist->Draw("TEXT SAME");

   c->cd(4); gPad->DrawFrame(0.,0.,1.,1.);
   TExec *ex4 = new TExec("ex4","gStyle->SetPaintTextFormat(\".0f\");");
   ex4->Draw();
   hist->Draw("TEXT SAME");
}

because SetPaintTextFormat is a global setting.

Couet,

Learn something useful (TExec class) every day!!!

Thank you.

Vi-Hoa