Multi histogram plot

Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.12/06
Platform: Not Provided
Compiler: Not Provided

Hi all,
I intend to draw several histograms on the same pad of a canvas, all of them without error bars but one
As a matter of fact, what happens is that ALL of the histograms conform to the choice (to have or not to have error bars) of the last histogram called to be drowned.
Why the previously drawn histograms lose their own “TH1F::Draw” option?
Thanks a lot.

The following is the fragment of code I am using:

  auto _legend = new TLegend(0.15,0.65,0.50,0.86);
  string hname("7_days_average_Italia_attualmente_positivi_");
  for(vector<TH1*>::iterator it=hT.begin(); it!=hT.end(); it++) {
    (*it)->GetYaxis()->SetRangeUser(0, maxy);	  
    (*it)->GetXaxis()->SetTitle("Giorni a partire dal 24 Feb. 2020");
    if((*it) == hT.front()) {
      cout<<*it)->GetName()) << " "  << (*it)->GetName() << endl;
      if(*it)->GetName()) == 0 )
	(*it)->Draw("E 9"); 
	(*it)->Draw("HIST P 9"); 
    } else {
      cout<<*it)->GetName()) << " "  << (*it)->GetName() << endl;
       if(*it)->GetName()) == 0 )
	 (*it)->Draw("SAME E 9");
	 (*it)->Draw("SAME HIST P 9"); 

It is not very clear which is the last histogram to be drawn.
Do you have a script we can run reproducing the issues.

All the the histograms of the vector container have to be drawn;
all of them without error bars, thus calling draw(“SAME HIST P”);
all except one, whose name is “7_days_average_Italia_attualmente_positivi_”, for which I call draw(“SAME E”).

You could take two histograms h1 and h2,
h1-> SetMarkerStyle(20);
h1->draw(“SAME HIST P”); // no error bar
h2->draw(“SAME E”); // error bar

BOTH come WITH error bar!!!
Or viceversa!

For me “P HIST” draws only the marker and “E” the marker and the error bars.
Can you post a .root file containing h1 et h2 ?

It’s complicated to use my code, which is a very large one.
Just look at included two figures: in one of them all the histograms exhibit the error bars; in the second no one does.

I needed the first histogram to display error bars by calling Draw("SAME E 9”) for it, while all the remaining not to display error bars, calling Draw("HIST P 9”) for them.
What happens instead is that ALL of the histograms appear without error bars BECAUSE the last histogram was drawn by Draw("HIST P 9”).

As counterevidence, I drew the last histogram by Draw("SAME E 9”) and all the preceding histogram were re-drawn WITH error bars!

errorbars.pdf (38.7 KB)

NOerrorbars.pdf (29.2 KB)

I used the simple script in the sequel and everything works as it should.
So something is wrong in my large program.
I will search for.
Thanks you.

TH1F *h1 = new TH1F("h1","test1",100,-4,4);
h1->SetMarkerStyle( 20) ;
h1->SetMarkerSize (0.65) ;
TH1F *h2 = new TH1F("h2","test2",100,-4,4);
h2->SetMarkerStyle( 20) ;
h2->SetMarkerSize (0.65) ;
TH1F *h3 = new TH1F("h3","test3",100,-4,4);
h3->SetMarkerStyle( 20) ;
h3->SetMarkerSize (0.65) ;
TCanvas c1("c1","test",10,10,700,900);
c1.Divide (1,2);;
h1->Draw("E 9");
h2->Draw("SAME HIST P 9");
h3->Draw("SAME HIST P 9");
h1->Draw("HIST P");
h2->Draw("SAME HIST P");
h3->Draw("SAME E");

Ok. Let us know if you need more help.

OK, I found the problem: a VEEEEERY trivial one!
Not to mention!!! :upside_down_face:
Thanks a lot!


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