How to apply TAxis::ChangeLabel to only a single axis

Hello,

I have two pads, the top pad will be used to plot two histograms and the bottom pad will be used to plot the ratio of the two histograms. In order to remove the ‘0’ label on the top plot (to avoid it appearing truncated) I am attempting to use the change label command to erase the ‘0’:

TCanvas* StackedCanvas = new TCanvas(FileName.c_str(), FileName.c_str(), 800, 800);                                                                                                                                                                              

const double TopSize = 0.7;                                                                                                                                                                                                                                   
const double BottomSize = 0.3;                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                   
TPad* MainPad  = new TPad("MainPad", "MainPad", 0., 1. - TopSize, 1., 1.);                                                                                                                                                                                       
MainPad->SetTopMargin(0.05);                                                                                                                                                                                                                                     
MainPad->SetBottomMargin(0);                                                                                                                                                                                                                                     
MainPad->SetRightMargin(0.05);                                                                                                                                                                                                                                   
TPad* RatioPad = new TPad("RatioPad", "RatioPad", 0., 0., 1., BottomSize);                                                                                                                                                                                       
RatioPad->SetTopMargin(0);                                                                                                                                                                                                                                       
RatioPad->SetBottomMargin(0.3);                                                                                                                                                                                                                                  
RatioPad->SetRightMargin(0.05);
 
MainPad->Draw();
MainPad->cd();
 
TH1F* A = new TH1F("h1","test1",100,-3,3);
A->FillRandom("gaus", 200000);                                                                                                                                                                                                                                   
A->SetLineColor(kRed);                                                                                                                                                                                                                                           
A->GetYaxis()->ChangeLabel(1, -1., 0.);                                                                                                                                                                                                                          
TH1F* B = new TH1F("h2","test2",100,-3,3);                                                                                                                                                                                                                       
B->FillRandom("gaus", 150000);                                                                                                                                                                                                                                   
B->SetLineColor(kBlue);                                                                                                                                                                                                                                          
A->Draw("HIST");                                                                                                                                                                                                                                                 
B->Draw("HIST SAME");                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                  
StackedCanvas->cd();                                                                                                                                                                                                                                             
RatioPad->Draw();                                                                                                                                                                                                                                                
RatioPad->cd();                                                                                                                                                                                                                                                  
TH1F* C = (TH1F*)A->Clone();                                                                                                                                                                                                                                     
C->Divide(B);                                                                                                                                                                                                                                                    
C->SetMinimum(0.5);                                                                                                                                                                                                                                              
C->SetMaximum(1.5);                                                                                                                                                                                                                                              
C->GetXaxis()->SetLabelSize(C->GetXaxis()->GetLabelSize() * TopSize / BottomSize);                                                                                                                                                                               
C->GetXaxis()->SetTitleSize(C->GetXaxis()->GetTitleSize() * TopSize / BottomSize);                                                                                                                                                                               
C->GetYaxis()->SetLabelSize(C->GetYaxis()->GetLabelSize() * TopSize / BottomSize);                                                                                                                                                                               
C->GetYaxis()->SetTitleSize(C->GetYaxis()->GetTitleSize() * TopSize / BottomSize);                                                                                                                                                                               
C->GetYaxis()->SetNdivisions(505);                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                    
C->Draw("HIST"); 

I only want to apply this to the top plot, the plot in the bottom pad also seems to be affected. The ‘0’ in the top plot is successfully removed, but the ‘0.6’ label in the bottom plot also seems to be removed. is there any way to apply the change label command to just the top y-axis?


ROOT Version: 6.24/06
Platform: Not Provided
Compiler: Not Provided


Move the “ChangeLabel” to somewhere after the “Clone” (or move the “Clone” to somewhere before the “ChangeLabel”).

1 Like

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