Making Plots
Note that when drawing a histogram in a canvas, you only append a reference to a histogram to the list of objects to be drawn, when the canvas is drawn. Thus, if you change the histogram, you'll also change the appearance of the histogram previously drawn on the canvas (when redrawing the canvas, e.g. for output into a ps-file). You'll need to h1->DrawCopy() in order to clone the histogram before appending a reference to the list of objects to be drawn.
Example:
c0->Clear();
c0->Divide(2,2);
c0->cd(1);
h1->DrawCopy();
// if you used h1->Draw(), you'd end up with
two identical histograms in the
eps-file
c0->cd(2);
h1->SetAxisRange(0.,
0.5);
h1->Draw();
c1->SaveAs("c1.eps");
How
to get a reasonable appearance
The default style of ROOT is
not to everybody's tast. Switch it off with
gROOT->SetStyle("Plain");
gROOT->ForceStyle();
You'll
get something quite similar to PAW.
How
to get reasonable colors
Ensure
that your Netscape has not emptied your color map, and
then
gStyle->SetPalette(1);
Colors
can be accessed by numbers (like in PAW) or with names:
enum
EColor { kWhite, kBlack, kRed, kGreen, kBlue, kYellow, kMagenta,
kCyan };
How to divide a Canvas into smaller canvases (aka
zone 2 2)
Assuming
you have a canvas c1, the CINT way is
c1->Clear();
c1->Divide(2,2);
// divisions in x and y
The GUI-way is to right-button
click into the Canvas context menu and
select Divide.
How
to get greek characters into an axis
title
h1->SetXTitle("`f#[degrees]");
How to get a logarithmic axis
This
is not in a histogram class, but a feature of pad, hence do
gPad->SetLogx(1);
// or SetLogy(1) or SetLogz(1). Turn off with SetLogx(0)
...
gPad->Modified()
Right-button
clicking into the Canvas context menu
gives you access to the same member functions.
How to get a grid
Again
a pad feature,hence
gPad->SetGrid(1);
// both axes get a grid, don't forget the gPad->Modified() (see
below)
gPad->SetGridx(1);
// x-axis only
gPad->SetGridy(1);
// y-axis only
gPad->Modified();
Same
functionality from the Canvas context menu
How to set th minimum and
maximum on a axis
h1->SetMinimum(0.5);
h1->SetMaximum(10.);
How
to draw only part of the histogram (aka h/pl
1(10.:20.))
In CINT,
do
h1->SetAxisRange(0.5,
1.5); // if you want to display from 0.5 to 1.5
You can also do it with the GUI, moving the cursor over the axis and left-clicking.A pair of lines will appear, one staying where you started, the other following your mouse movements.
How to get a Legend
From
CINT (or a macro) do the following (assuming you have a histogram
h1):
pl
= new Tlegend(0.4,0.2,0.85,0.35); // coordinates are in
fractions of pad dimensions
pl->SetHeader("Legend
Title");
pl->SetTextSize(0.04);
// set size of text
pl->SetMarkerSize(1.4);
// increase markersize so that they are visible
pl->SetFillColor(0);
// Have a white background
ple =
pl->AddEntry(h1, "text 1", "p"); // p
shows points, other options exist (Check documentation)
pl->Draw()
How
to get a box with text
A
text box with lines of text is produced with
pt
= new TPaveText(0.20,0.7,0.5,0.87, "NDC"); //
NDC sets coordinates relative to pad dimensions
pt->SetFillColor(0);
// text is black on
white
pt->SetTextSize(0.04);
pt->SetTextAlign(12);
text = pt->AddText("Whatever you want");
How
to make non-default axis labels with larger symbols and greek
letters
The following shows
how to get large labels, axis titles, greek fonts onto a
histogram
gPad->SetLeftMargin(0.15);
// experiment with the best value for you.
Depends on font size,
..
gPad->SetBottomMargin(0.15);
h->SetLabelSize(0.05,
"y");
h->GetYaxis()->SetTitleSize(0.05);
h->SetLabelSize(0.05,
"x");
h->GetXaxis()->SetTitleSize(0.05);
h1->SetXTitle("`f#[degrees]");
// just like PAW, see below or other
possibilities
h1->SetYTitle("Entries / bin");