Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
gr104_palettecolor.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Palette coloring for graphs 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 TGraph::Draw the TGraph 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 graphs are displayed with palette coloring for lines and and filled area. The graphs are drawn with curves (C option) and one can see the color of each graph is picked inside the palette kSolar. The same is visible on filled polygons in the automatically built legend. To have more control on the legend, it can be created manually, see the graph tutorial gr111_legend.C

E ua␅

void gr104_palettecolor () {
gStyle->SetOptTitle(kFALSE);
gStyle->SetPalette(kSolar);
double x[5] = {1,2,3,4,5};
double y1[5] = {1.0,2.0,1.0,2.5,3.0};
double y2[5] = {1.1,2.1,1.1,2.6,3.1};
double y3[5] = {1.2,2.2,1.2,2.7,3.2};
double y4[5] = {1.3,2.3,1.3,2.8,3.3};
double y5[5] = {1.4,2.4,1.4,2.9,3.4};
TGraph *g1 = new TGraph(5,x,y1); g1->SetTitle("Graph with a red star");
TGraph *g2 = new TGraph(5,x,y2); g2->SetTitle("Graph with a circular marker");
TGraph *g3 = new TGraph(5,x,y3); g3->SetTitle("Graph with an open square marker");
TGraph *g4 = new TGraph(5,x,y4); g4->SetTitle("Graph with a blue star");
TGraph *g5 = new TGraph(5,x,y5); g5->SetTitle("Graph with a full square marker");
// The Draw option "A" (draw axes) is needed (only) for the first drawn graph
g1->Draw("CA* PLC PFC");
g2->Draw("PC PLC PFC");
g3->Draw("PC PLC PFC");
g4->Draw("*C PLC PFC");
g5->Draw("PC PLC PFC");
gPad->BuildLegend();
}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
@ kRed
Definition Rtypes.h:67
@ kBlue
Definition Rtypes.h:67
@ kOpenSquare
Definition TAttMarker.h:61
@ kCircle
Definition TAttMarker.h:58
@ kFullSquare
Definition TAttMarker.h:60
@ kSolar
Definition TColor.h:135
externTStyle * gStyle
Definition TStyle.h:442
#define gPad
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
void SetTitle(const char *title="") override
Set the title of the TNamed.
Double_t x[n]
Definition legend1.C:17
Author
Olivier Couet

Definition in file gr104_palettecolor.C.