Consider this example:
TH1 * h = new TH1F("h", "h", 10, 0.0, 10.0);
TLegend * legend = new TLegend(0.5, 0.5, 0.9, 0.9);
legend -> AddEntry(h, "hist", "l");
printf("legend params before canvas drawn x1 %f y1 %f x2 %f y2 %f\n", legend -> GetX1(), legend -> GetY1(), legend -> GetX2(), legend -> GetY2());
TCanvas *c = new TCanvas;
h -> Draw();
legend -> Draw("SAME");
c -> SaveAs("testcanvas.png");
printf("legend params after canvas drawn x1 %f y1 %f x2 %f y2 %f\n", legend -> GetX1(), legend -> GetY1(), legend -> GetX2(), legend -> GetY2());
The text output is:
legend params before canvas drawn x1 0.500000 y1 0.500000 x2 0.900000 y2 0.900000
Info in <TCanvas::Print>: file testcanvas.png has been created
legend params after canvas drawn x1 5.000000 y1 0.525000 x2 10.000000 y2 1.050000
Why drawing the canvas changes legend parameters? That creates problems when resaving the canvas further in the program.
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided