Different plots of the same histogram in two subdivision of a canvas

Hello!

I want to plot same histogram in one canvas such that the first part will show normal axes while the second one will show the same with log x including change in X axis label. I tried the following but it changed axes lable as per last line.

TFile* tf1 = new TFile("myFile.root"); TH2* myTH2 = (TH2*) tf1->Get("NeutronEnergy"); .... TCanvas* c1 = new TCanvas("c1", "myText", 1200, 800); c1->Divide(2,1); c1->cd(1); myTH2->SetMarkerStyle(7); myTH2->GetXaxis()->SetTitle("X Label"); myTH2->GetYaxis()->SetTile("Y Label"); myTH2->Draw(); c1->cd(2); myTH2->SetLogx(); myTH2->GetXaxis()->SetTitle("log10(X Label)"); // I want change here myTH2->GetYaxis()->SetTile("Y Label"); myTH2->Draw();
Please let me know how may I plot two plots of same histogram in divided canvas with two different axes labels.

Thanks and Regards
Abhijit Bhattacharyya


_ROOT Version:6.13
_Platform: Ubuntu 18.10
_Compiler:


{
  TFile *tf1 = TFile::Open("myFile.root");
  TH2F *myTH2; tf1->GetObject("NeutronEnergy", myTH2);
  
  myTH2->GetXaxis()->SetTitle("X Label");
  myTH2->GetXaxis()->SetTitleOffset(1.3);
  myTH2->GetYaxis()->SetTitle("Y Label");
  myTH2->GetYaxis()->SetTitleOffset(1.3);
  myTH2->SetMarkerStyle(7);
  
  TCanvas* c1 = new TCanvas("c1", "myText", 1200, 800);
  c1->Divide(2,1);
  c1->cd(1);
  myTH2->Draw();
  c1->cd(2);
  gPad->SetLogx(1);
  TH1 *h = myTH2->DrawCopy();
  h->GetXaxis()->SetTitle("X Label shown in log10 scale");
  c1->cd(0);
}
1 Like

Hi Wile_E_Coyote!

Thank you very much for the technique that solved the issue. Can you kindly tell me how may I format y axis so that Y axis tic numbers will not superimpose on the y axis label? That means there will be some gap between y axis label and the y axis tics numbers?

Best Regards
Abhijit

Try something like: myTH2->GetYaxis()->SetTitleOffset(1.5);

1 Like

Thanks a lot. Fantastic.
Best,
Abhijit

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