Multiple Profile Histograms on the same pad, same canvas

Hi
I have four kinds of different data and want to draw some 4 different profile histograms for them, but on the same pad with different marker styles. Same as in the photo.

How can I do it?
Thankyou
:slight_smile:

You draw the first histogram without option SAME and all the others on top using option SAME.
You can change the marker style of the histogram using the SetMarkerStyle method and the colour using SetMarkerColor. Your question is very general and without a small script as starting point it is hard to help you. I would recommend you also check the THistPainter class in the ROOT reference Guide. And look also at the tutorials.

Hello I am using the following code for this. But It is drawing in the different canvases.

   TFile *f = new TFile("v2_vs_pT.root", "RECREATE");  
    TCanvas *Ell_flow = new TCanvas ("Elliptic Flow kaon","flow",15,15,700,500);
   gStyle->SetOptStat(kFALSE); 
   
   
   gStyle->SetTitleFontSize(0.2);
   V2hist->Draw("E4");
   V2hist->SetTitle("p_{T} dependence of v_{2} for '#Kappa^{+} + #Kappa^{-}'"); 
   V2hist->SetMarkerStyle(kFullTriangleUp);
   V2hist->SetMarkerColor(kBlue);
   V2hist->GetYaxis()->SetTitleOffset(1.4);
   V2hist->GetYaxis()->CenterTitle(true);
   V2hist->GetYaxis()->SetTitle("v_{2}");
   
   V2hist->GetXaxis()->SetTitleOffset(1.4);
   V2hist->GetXaxis()->CenterTitle(true);
   gStyle->SetTitleFontSize(0.2);
   V2hist->GetXaxis()->SetTitle("p_{T}(GeV/c)");
   V2hist->Write();
   Ell_flow->Update();
   
   gStyle->SetTitleFontSize(0.2);
   
   V2hist211->SetTitle("p_{T} dependence of v_{2} for '#pi^{+} + #pi^{-}'"); 
   V2hist211->SetMarkerStyle(kFullCircle);
   V2hist211->SetMarkerColor(kRed);
   V2hist211->GetYaxis()->SetTitleOffset(1.4);
   V2hist211->GetYaxis()->CenterTitle(true);
   gStyle->SetTitleFontSize(0.2);  
   V2hist211->GetYaxis()->SetTitle("v_{2}");
    
   V2hist211->GetXaxis()->SetTitleOffset(1.4);
   V2hist211->GetXaxis()->CenterTitle(true);
   gStyle->SetTitleFontSize(0.2); 
   V2hist211->GetXaxis()->SetTitle("p_{T}(GeV/c)");
   
   V2hist211->Draw("same");
   V2hist211->Write();
   
   gStyle->SetTitleFontSize(0.2);
   
   V2hist2212->SetTitle("p_{T} dependence of v_{2} for 'p + #topbarp'"); 
   V2hist2212->SetMarkerStyle(kFullTriangleDown);
   V2hist2212->SetMarkerColor(kBlack);
   V2hist2212->GetYaxis()->SetTitleOffset(1.4);
   V2hist2212->GetYaxis()->CenterTitle(true);
   V2hist2212->GetYaxis()->SetTitle("v_{2}");
   
   V2hist2212->GetXaxis()->SetTitleOffset(1.4);
   V2hist2212->GetXaxis()->CenterTitle(true);
   V2hist2212->GetXaxis()->SetTitle("p_{T}(GeV/c)");
   V2hist2212->Draw("same");
   V2hist2212->Write();

It should not. Your code creates only one canvas.

Can you please tell Is this code able to write the histograms in the same canvas?

You “Draw” in a canvas you do not “Write”… Yes your code creates one single Canvas and Draw the histograms in it … but It is a bit bizarre… where do you get the histogram from ? if it is from the root file you open with TFile you should not open it with RECREATE … and also I do not understand why you Write the histograms again if they are already in the file …

This is just a snippet of code. I am declaring the histograms in a header file and then filling and writing them to a root file. I am not taking the histograms from any root file.

In that case post an example we can run so we can modify it to make it work. Right now what you posted cannot be executed as it is.

Solved :wink:
The same code is working for histogram. I didn’t write it to any root file.
Thank you

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