Plotting histograms in the same window

Hi everybody.

I am new to root, so if any of what I say sounds silly, bear with me please. I want to plot several histograms in the same window. I generated the histograms with TTree and I don’t use the Draw() function. Rather, I only use the Write() to write the histograms and then open them with the TBrowser.

Is there a way of merging them in the same window without using Draw()?


When you visualise histograms using TBrowser there is an input field called “Draw option”.

You should put the option “SAME” in that field when you want to draw an histogram on top of the already plotted one…

I am curious to know why you are against using Draw() ? TBrowser is fine to scan quickly histograms in a file but as soon as you will produce more complex plots you will quickly hit the limits of this tool.

1 Like

Hi Olivier and thank you for your reply.

Using the TBrowser does the job, for now. Sorry I did not mean to say that I refuse to use the Draw() option; I tried and couldn’t make it work, therefore I was looking for an alternative to it.

I will try to post only the relevant lines of code without overloading the post.

The plots I want to superimpose are defined as

TH1D *hFlux[nParents][nprodw]; // nParents and nprodw range from 0 to 4 and 0 to 7, respectively. . . . for (int i=0;i<nParents;i++) { for (int j=0;j<nprodw;j++){ hFlux[i][j] = new TH1D(Form("h%s_Flux",parP_w[i][j].c_str()), Form("h%s_Flux",parP_w[i][j].c_str()), 100,0.,15.); } } . . . hFlux[i][j]->Fill(nu_e,wflux); . . . TFile *histFile=new TFile(flnm.c_str(),"RECREATE"); . . . for (Int_t i=0;i<nParents;i++) { for (int j=0;j<nprodw;j++){ hFlux[i][j] -> Write(); . . . } histFile->Close();

And the I delete them.
Where should I put the Draw() option here?

Thank you.

 for (Int_t i=0;i<nParents;i++) {
  for (int j=0;j<nprodw;j++){
   hFlux[i][j] -> Draw("SAME");

At some point you may also want to make sure the global range of all the histograms is calculated automatically. In that case the class THStack will help you.

Thank you.

This somehow did not work. I can compile and run the code, but no histograms are drawn on the same window. It is as before.

At that point a small macro reproducing the problem and showing what you are really doing might be needed to help you further.

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