Histogram (TH2F) title size

I’d like to change the font size of my histogram.
I read histograms from file and then put them on a canvas which is divided into 9 blocks, 3x3.
I’m able to change the style of X, Y axis by

h->SetTitleSize(0.06, "XY"); h->SetLabelSize(0.05, "XY");
and so on. But cannot get title to change.
Here is the part of my code:

[code] gStyle->SetTitleFontSize(0.07); // doesn’t work

std::vector<TCanvas*> c;

for (int j = 0; j < 9; j++) {

	str << "c" << j;
	c.push_back(new TCanvas(str.str().c_str(), str.str().c_str(), 1200, 1200));
	str.str("");

	
	c.at(j)->Divide(3,3);

	for (int i = 0; i < 1; i++)
	{
		str << "h" << j << "GeV" << i;
		TKey 	*key1 = f->FindKey(str.str().c_str());
		str.str("");

		if (key1 == 0)
			std::cout << "error" << std::endl;
		else {
			str << "h" << j << "GeV" << i;
			TH2F *h1 = (TH2F*) f->Get(str.str().c_str());
			str.str("");

			c.at(j)->cd(i+1);

			h1->SetTitleSize(0.06, "XY");
			h1->SetLabelSize(0.05, "XY");

			h1->GetXaxis()->SetTitle("cos#theta");
			h1->GetYaxis()->SetTitle("#phi");
			h1->GetXaxis()->CenterTitle();
			h1->GetYaxis()->CenterTitle();
			h1->GetXaxis()->SetNdivisions(505);
			h1->GetYaxis()->SetNdivisions(605);

			h1->Draw("SURF3");
		}
	}
	c.at(j)->Update();
	str << "c" << j << ".pdf";
	c.at(j)->SaveAs(str.str().c_str());
	str.str("");
}[/code]

The best way to find out what is the command to be used to perform that kind of changes, is to edit your histogram interactively with the mouse and then save the result as a .C file. Then you will find the answer in the .C file.

2 Likes