Re: [ROOT] Horizontal Histogramming

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Aug 28 2001 - 12:45:39 MEST


Hi Alan,

Currently we have no options to draw an histogram with horizontal bars.

You can use the following macro:

Rene Brun

void hori(TH1 *h) {
   //Draw histogram h horizontaly with bars
   Double_t ymin = h->GetMinimum();
   Double_t ymax = 1.05*h->GetMaximum();
   TAxis *axis   = h->GetXaxis();
   Double_t xmin = axis->GetXmin();
   Double_t xmax = axis->GetXmax();
   Int_t nbins   = axis->GetNbins();
   TH2F *h2 = new TH2F("h2",h->GetTitle(),10,ymin,ymax,nbins,xmin,xmax);
   h2->SetBit(kCanDelete);
   h2->SetDirectory(0);
   h2->SetStats(0);
   h2->Draw();
   TBox box;
   Int_t color = h->GetFillColor();
   if (color == 0) color = 1;
   box.SetFillColor(color);
   Double_t dy;
   Double_t x1,y1,x2,y2;
   for (Int_t i=1;i<=nbins;i++) {
      dy = axis->GetBinWidth(i);
      x1 = 0;
      y1 = axis->GetBinCenter(i)-0.3*dy;
      x2 = h->GetBinContent(i);
      y2 = axis->GetBinCenter(i)+0.3*dy;
      box.DrawBox(x1,y1,x2,y2);
   }
}

Alan Barr wrote:
> 
> Dear rooters,
> 
> Is there a way to plot a 1-dimensional histogram rotated by 90 degrees so
> that the bars are horizontal?
> 
> Alan



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:58 MET