Logo ROOT  
Reference Guide
histpalettecolor.C File Reference

Detailed Description

View in nbviewer Open in SWAN Palette coloring for histogram is activated thanks to the options PFC (Palette Fill Color), PLC (Palette Line Color) and AMC (Palette Marker Color). When one of these options is given to TH1::Draw the histogram get its color from the current color palette defined by gStyle->SetPalette(...). The color is determined according to the number of objects having palette coloring in the current pad.

In this example five histograms are displayed with palette coloring for lines and and marker. The histograms are drawn with makers and error bars and one can see the color of each histogram is picked inside the default palette kBird.

void histpalettecolor()
{
auto C = new TCanvas();
auto h1 = new TH1F ("h1","Histogram drawn with full circles",100,-4,4);
auto h2 = new TH1F ("h2","Histogram drawn with full squares",100,-4,4);
auto h3 = new TH1F ("h3","Histogram drawn with full triangles up",100,-4,4);
auto h4 = new TH1F ("h4","Histogram drawn with full triangles down",100,-4,4);
auto h5 = new TH1F ("h5","Histogram drawn with empty circles",100,-4,4);
TRandom3 rng;
Double_t px,py;
for (Int_t i = 0; i < 25000; i++) {
rng.Rannor(px,py);
h1->Fill(px,10.);
h2->Fill(px, 8.);
h3->Fill(px, 6.);
h4->Fill(px, 4.);
h5->Fill(px, 2.);
}
h1->SetMarkerStyle(kFullCircle);
h2->SetMarkerStyle(kFullSquare);
h3->SetMarkerStyle(kFullTriangleUp);
h4->SetMarkerStyle(kFullTriangleDown);
h5->SetMarkerStyle(kOpenCircle);
h1->Draw("PLC PMC");
h2->Draw("SAME PLC PMC");
h3->Draw("SAME PLC PMC");
h4->Draw("SAME PLC PMC");
h5->Draw("SAME PLC PMC");
gPad->BuildLegend();
}
Author
Olivier Couet

Definition in file histpalettecolor.C.

kOpenCircle
@ kOpenCircle
Definition: TAttMarker.h:52
Int_t
int Int_t
Definition: RtypesCore.h:45
h1
TH1F * h1
Definition: legend1.C:5
ROOT::Math::Cephes::C
static double C[]
Definition: SpecFuncCephes.cxx:187
TRandom::Rannor
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:489
kFullCircle
@ kFullCircle
Definition: TAttMarker.h:51
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
kFullTriangleUp
@ kFullTriangleUp
Definition: TAttMarker.h:51
TRandom3
Definition: TRandom3.h:27
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
TStyle::SetOptStat
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1592
TStyle::SetOptTitle
void SetOptTitle(Int_t tit=1)
Definition: TStyle.h:318
TH2::Fill
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:294
kFullSquare
@ kFullSquare
Definition: TAttMarker.h:51
Double_t
double Double_t
Definition: RtypesCore.h:59
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
gPad
#define gPad
Definition: TVirtualPad.h:287
kFullTriangleDown
@ kFullTriangleDown
Definition: TAttMarker.h:52
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997