{
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i = 0; i < n; i++) {
x[i] = i * 0.1 + 0.05;
y[i] = 10.0 * sin(x[i] + 0.2);
}
TGraph *gr = new TGraph(n, x, y);
TCanvas *c1 = new TCanvas("c1", "c1");
TH1F *hf = gPad->DrawFrame(0., 1., 3., 12., // xmin, ymin, xmax, ymax
"global title;X title;Y title;Z title");
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
#if 0 /* 0 or 1 */
hf = ((TH1F *)(gPad->FindObject("hframe")));
#endif /* 0 or 1 */
// hf->SetTitle("novel global title;novel X title;novel Y title;novel Z title");
gr->Draw("*");
// hf->SetTitle("new global title;new X title;new Y title;new Z title");
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
}
{
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i = 0; i < n; i++) {
x[i] = i * 0.1 + 0.05;
y[i] = 10.0 * sin(x[i] + 0.2);
}
TGraph *gr = new TGraph(n, x, y);
TMultiGraph *mg = new TMultiGraph("mg",
"global title;X title;Y title;Z title");
mg->Add(gr, "*");
TCanvas *c1 = new TCanvas("c1", "c1");
// mg->SetTitle("novel global title;novel X title;novel Y title;novel Z title");
mg->Draw("A");
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
// mg->GetHistogram()->SetTitle("new title;new X title;new Y title;new Z title");
#if 1 /* 0 or 1 */
mg->GetXaxis()->SetLimits(0., 3.); // xmin, xmax
mg->GetHistogram()->SetMinimum(1.); // ymin
mg->GetHistogram()->SetMaximum(12.); // ymax
#else /* 0 or 1 */
mg->GetXaxis()->SetLimits(0., 3.); // xmin, xmax
mg->GetYaxis()->SetRangeUser(1., 12.); // ymin, ymax
// mg->GetHistogram()->SetAxisRange(1., 12., "Y"); // ymin, ymax
#endif /* 0 or 1 */
gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
}
See also:
[url]Order of calling methods with TMultiGraph
[url]Setting titles for TGraphs
[url]SetRangeUser and SetTitle working with THStacks and TH1F obj
[url]SetAxisRange(0.0,1.0,“Y”); is ineffective
[url]Palette on a TProfile2d
[url]SetRangeUser doesn’t work well
[url]Drawing a TGraphAsymmErrors