Re: Histogram Look

Rene Brun (Rene.Brun@cern.ch)
Fri, 27 Feb 1998 14:46:08 +0100


Scott Sampson wrote:
>
> Hi,
>
> I want to change global defaults to make my histograms look nicer.
> Ideally, I would like to put the changes in my rootlogon.C file, so that
> everything I plot would have these settings. Some of the things I would
> like to change are
>
> 1) the default font (and font size) in the stats box
> 2) the default font (and font size) on the axis labels
> 3) the default title font and size
> 4) the distance between the axis labels and the axis
> 5) the borders of the histogram within the pad
> 6) perhaps the position of the stats box?
>
> It would be nice if these new settings were used regardless of what I
> plotted, a histogram, a graph, or whatever.

Most of these parameters can be customized via the TStyle class.
Root provides a default style pointed by gStyle.
In your rootlogon.C file, you can redefine the default parameters
via statements like:
gStyle->SetStatX(0.7);
gStyle->SetStatW(0.2);
gStyle->SetLabelOffset(1.2);
gStyle->SetLabelFont(72);

(see complete list of options in class TStyle)

An interesting possibility is to switch between styles.
In addition to the default style, you can create your own styles.
For example:
TStyle *st1 = new TStyle("st1");
st1->Set....
st1->cd(); this becomes now the current style gStyle

you can change to a new style, using the style name with:

gROOT->GetStyle("default")->cd();

Note that when an object is created, its attributes are taken from the
current style. For example, you may have created an histogram in a
previous session, saved it in a file. Meanwhile, if you have changed
the style, the histogram will be drawn with the old attributes.
Now, let's assume you have a canvas with your histogram or any other
object, you can force a redrawing of the canvas via
gROOT->ForceStyle();

>
> Another things that would be nice: when I have a plot with a stats
> box, and then superimpose another plot with the "SAME" option, I would
> also like to get a stats box for the second plot, perhaps underneath the
> first, or maybe a new stats box with info from both plots, (or both plots
> and their respective fits). I realize this is a lot to ask, but is it
> possible? Again, it would be nice if it could be set up as the default
> behavior everytime I use a ->Draw(..) command.
>
> Thanks,
>
> Scott

The algorithm currently used is to plot the stats box only for the first
histogram drawn in a pad. Like many other things already possible in
Root,
and not yet documented, I want to mention a very interesting feature.
You can add your own objects to a special list (the list of functions)
associated to an histogram, graph. This object will be automatically
drawn when the histogram is repainted.
Example:
TPaveText *pt = new TPaveText(xmin,ymin,xmax,ymax); //coord are hist
coord
pt->AddText("annotation 1")
pt->AddText("annotation 2")
h->GetListOfFunctions()->Add(pt);

now, doing h->Draw() will also paint the pt object.
Coming back to your request, you can for example add the result of
some computation.
Float_t myval = h->GetSum();
char text[50]
sprintf(text,"My value =%f",myval);
pt->AddText(text);

Rene Brun