Re: [ROOT] set bin colour

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Mon Sep 02 2002 - 13:49:47 MEST


Hi Christian, 

On Mon, 2 Sep 2002 12:19:41 +0200 (MET DST)
Christian.Doerr@mpi-hd.mpg.de wrote
concerning "[ROOT] set bin colour":
> Hello everybody,
> 
> I just wondered whether there is a way to set the colours for each bin
> in a histogram individually?!

Draw several histograms on top of each other, each with thier own fill
colour, or draw boxes bound by the histogram bins. 

  TH1* h = new TH1D("h", "h", 6, -3, 3); 
  h->FillRandom("gaus"); 
  h->Draw("axis"); 

  for (Int_t i = 0; i < h->GetNbinsX(); i++) { 
    TH1* b = new TH1D(Form("b%d", i), "b", h->GetNbinsX(), 
                      h->GetXaxis()->GetXmin(),
                      h->GetXaxis()->GetXmax());
    b->SetBinContent(i+1, h->GetBinContent(i+1));
    b->SetFillColor(i+1); 
    b->Draw("same"); 
  }

Yours, 

 ____ |  Christian Holm Christensen 
  |_| |	 -------------------------------------------------------------
    | |	 Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|	          DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|	          Denmark                    Office: (+45) 353  25 305
 ____|	 Email:   cholm@nbi.dk               Web:    www.nbi.dk/~cholm
 | |



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:06 MET