How to fillcolor at selected Bins of TH1D class object?

I want to fillcolor at the Bins with Bin number bigger than 10 on a TH1D class object, but the code below:

hist3->SetFillColor(2);

fill all the Bins,


can i only fillcolor at at the Bins selected?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


{
  auto *h1 = new TH1F("h1","Histo 1",100,-5,5);
  h1->FillRandom("gaus",10000);
  h1->SetFillStyle(1001);
  h1->SetFillColor(kRed);
  h1->Draw();

  auto h2 = h1->DrawCopy("SAME");
  h2->GetXaxis()->SetRangeUser(1.,2.);
  h2->SetFillStyle(1001);
  h2->SetFillColor(kBlue);
}

1 Like

thanks!

To TGraph class, it seems no resolution DrawCopy(), with TGraph class, how shauld i do?

This technique will not work for graphs. Here is a possible way.

{
   auto *g1 = new TGraph();
   g1->AddPoint(0,1);
   g1->AddPoint(1,2);
   g1->AddPoint(2,3);
   g1->AddPoint(3,4);
   g1->AddPoint(4,5);
   g1->AddPoint(5,5);
   g1->AddPoint(6,4);
   g1->AddPoint(7,3);
   g1->AddPoint(8,2);
   g1->AddPoint(9,1);
   g1->Draw("AB");
   g1->SetFillColor(kRed);

   auto g2 = (TGraph*)g1->Clone();
   g2->SetFillColor(kBlue);
   g2->SetPointY(0,0);
   g2->SetPointY(1,0);
   g2->SetPointY(2,0);
   g2->SetPointY(3,0);
   g2->SetPointY(4,0);
   g2->Draw("B");
}

thanks!

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