How can I SetFillColor for exact one bin of my TH1 histogram?
Is it possible?
void PaintBin (TH1 *h, Int_t bin, Int_t color) 
{
   printf("%d %d %d\n", bin, color, h->GetBinContent(bin));
   TBox *b = new TBox(h->GetBinLowEdge(bin),
                      h->GetMinimum(),
                      h->GetBinWidth(bin)+h->GetBinLowEdge(bin),
                      h->GetBinContent(bin));
   b->SetFillColor(color);
   b->Draw();
}
void bincolor()
{
  TH1F *h1 = new TH1F("h1","h1",100,-10,10);
  h1->FillRandom("gaus");
  h1->Draw();
  PaintBin (h1, 60, kRed);
  PaintBin (h1, 50, kBlue);
}
              
              
              1 Like
            
            
          It’s great, thanks.
This code should be a standart root SetBinColor.
Well, that’s just a single box at the right place … 
Thanks a lot. That’s perfect and beautiful solution!!!
              
              
              1 Like