How to set the exact TCanvas size?

Hi!

I think I don’t fully understand one of the constructor of a TCanvas.

Try this:

{
	Double_t x, y;
	
	gStyle->SetOptStat(false);
	TCanvas * c = new TCanvas("canvas", "window", 500, 500);
	TH2D * h = new TH2D("h", "Title;x;y", 50, -5, 5, 50, -5, 5);

	for (Int_t i = 0; i < 1E+4; i++) {
		gRandom->Rannor(x, y);
		h->Fill(x, y);
	}

	h->Draw("COLZ");
	c->SaveAs("test.png");
	return c;
}

I’d expect that the test.png image is exactly 500x500 pixel, because those are the numbers I set in the TCanvas. Why I get 498x474? It’s not even a square.

How do I need to edit that macro in order to get output images with exactly the size I want?

Thanks!

Search for “size” in the TCanvas Class Reference.

1 Like

:no_mouth:
That was easy…

Thanks!

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