Re: [ROOT] Fill problem with TGraph Draw

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Jan 20 2001 - 09:59:26 MET


Hi Tony,
When you use the fill option of a TGraph, the area delimited
by the set of N points x[N],y[N] is filled.
A TGraph IS NOT an histogram. In case of TH1s, the assumption for the fill
area
is to start at the minimum of the histogram.
If this is simply what you want, here is a simple macro to do the job.

Rene Brun

{
 Int_t    i,  num_points;
 gStyle->SetCanvasColor(0);
 gStyle->SetPadGridX(1);
 gStyle->SetPadGridY(1);
 TCanvas *canvas = new TCanvas("canvas","my plot",10,10,500,600);

 num_points = 1000;
 TH1F *h = new TH1F("h","title",num_points,0,num_points);
 for (i = 0; i<num_points; i++){
   h->SetBinContent(i+1,3);
 }

 h->SetFillColor(6);
 h->SetMaximum(10);
 h->Draw();
}


On Fri, 19 Jan 2001, Tony Vaiciulis wrote:

> 
> Hi,
> 
> I run the following macro to plot a constant value using the TGraph Draw()
> method. The horizontal axis has range 0 to 999, with a total of 1000 bins. 
> I set the constant value on the vertical axis to be 3 in this example. By
> using the fill option of the Draw() method, I expect to see a rectangle of
> height 3 and length 1000, completely filled in with the fill color of my
> choice. Instead I see erratic behavior with the 'fill' option UNLESS I
> explicitly set to zero the bins 203, 406, 609, 812. Has anyone else seen
> strange behavior with the fill option when making a plot with many bins?
> My current work around is, unfortunately, to avoid using the fill option.
> 
> thanks,
> Tony
> 
> int mytest()
> {
>  Float_t  x_values[2016]; 
>  Float_t  y_values[2016];
> 
>  Int_t    i;
>  Float_t  num_points;
> 
>  gROOT->Reset();
>  gStyle->SetCanvasColor(0);
>  gStyle->SetPadGridX(1);
>  gStyle->SetPadGridY(1);
> 
>  num_points = 1000;
>  for (i = 0; i<num_points; i++){
>    x_values[i] = i;
>  }
>  for (i=0; i<num_points; i++){
>   y_values[i] = 3;
>  }
> 
>  // Reset end points to zero (to avoid unwanted display features of
>  // 'fill' option of Draw() ).
>   y_values[0]            = 0;
>   y_values[num_points-1] = 0;
> 
>  // For some reason I need the next four lines.
>  y_values[203] = 0;  // Erratic fill behavior if commented out
>  y_values[406] = 0;  // Erratic fill behavior if commented out
>  y_values[609] = 0;  // Erratic fill behavior if commented out
>  y_values[812] = 0;  // Erratic fill behavior if commented out
> 
>  TCanvas *canvas = new TCanvas("canvas","my plot",10,10,500,600);
>  TGraph *Graph = new TGraph(num_points, x_values, y_values);
>  Graph->SetFillColor(6);
>  Graph->SetMaximum(10);
>  Graph->Draw("ALF");  // draw with fill option
> 
>  return 0;
> }
> 
> 



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