Re: [ROOT] A simple question about histogram attributes

From: Stephen Bailey (bailey@physics.harvard.edu)
Date: Sat May 20 2000 - 21:14:04 MEST


Hi.

SetHistLineStyle is part of TStyle.  You use that to set what
the default line style is for all subsequently created histograms.
e.g.  gStyle->SetHistLineStyle(2) will make all future histograms
with dashed lines.

To change the line style of an individual histogram, use
SetLineStyle.  It is hidden down in the AttLine class which
TH1 inherits from.  The options are listed in the class description
for AttLine:

  *-*-*-*-*-*-*-*-*-*-*-*-*Line Attributes class*-*-*-*-*-*-*-*
  *-*                      =====================
  *-*  Line attributes are:
  *-*    Line Color (see TAttFill for the list of colors)
  *-*    Line Style 1=solid, 2=dash, 3=dash-dot, 4=dot-dot
  *-*    Line Width expressed in pixel units
  *-*
  *-*  This class is used (in general by secondary inheritance)
  *-*  by many other classes (graphics, histograms).
  *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

e.g. you probably want to do something like:

  h1->SetLineStyle(1);
  h2->SetLineStyle(2);
  h3->SetLineStyle(3);
  h4->SetLineStyle(4);

  h1->Draw();
  h2->Draw("same");  h3->Draw("same");  h4->Draw("same");

If you want to create several histograms with solid lines
followed by several with dashed lines, you could do something
like:

 gStyle->SetHistLineStyle(1);
 TH1F* h1 = new TH1F("h1", "Solid Line", 100, 0, 20);
 TH1F* h2 = new TH1F("h2", "Solid Line", 100, 0, 20);
 TH1F* h3 = new TH1F("h3", "Solid Line", 100, 0, 20);

 gStyle->SetHistLineStyle(2);
 TH1F* h4 = new TH1F("h4", "Solid Line", 100, 0, 20);
 TH1F* h5 = new TH1F("h5", "Solid Line", 100, 0, 20);
 TH1F* h6 = new TH1F("h6", "Solid Line", 100, 0, 20);

rather than having to individually set the line style on
each histogram.

Similar comments apply to TStyle::SetHistFillColor() vs.
AttFill::SetFillColor().

I hope that helps.

Stephen


On Sat, 20 May 2000, Claire Gwenlan wrote:

> 
> Hi Everybody,
> 
> Sorry about another simple question (my only excuse is that I've only just
> started!). I want to plot a very simple set of histograms (in black and 
> white) all overlayed onto each other, so I basically want to choose lots
> of different line styles eg. dashed, dotted etc. I've looked at all the
> documentation and I thought that maybe  SetHistLineStyle will
> do the trick.
> 
> Firstly, am I right in thinking this?
> Secondly, is there a list that gives all the possible options?
> Thirdly, and most importantly, if this is the correct thing to use, I
> can't get it to work by typing, for example,
> 
> h1->SetHistLineStyle(somenumber);
> 
> if my histogram is h1. The error that comes up is the following:
> 
> Error: Can't call TH1F::SetHistLineStyle() in current scope
> FILE:/tmp/file9uApj4_cint LINE:1
> Possible candidates are...
> filename       line:size busy function type and name  (in TH1F)
> filename       line:size busy function type and name  (in TH1)
> filename       line:size busy function type and name  (in TNamed)
> filename       line:size busy function type and name  (in TObject)
> filename       line:size busy function type and name  (in TAttLine)
> filename       line:size busy function type and name  (in TAttFill)
> filename       line:size busy function type and name  (in TAttMarker)
> filename       line:size busy function type and name  (in TArrayF)
> filename       line:size busy function type and name  (in TArray)
> *** Interpreter error recovered ***
> 
> So, what do I need to do?
> 
> Thanks a lot,
> 
> Claire
> 
>  __________________________________
>  Claire Gwenlan
>  Department of Physics & Astronomy
>  University College London
>  Gower Street
>  LONDON
>  WC1E 6BT
> 
>  Tel: (0171) 419 3454
> _________________________________
> 



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:25 MET