Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
gr104_palettecolor.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphs
3/// \notebook
4/// \preview Palette coloring for graphs is activated thanks to the options PFC (Palette Fill Color),
5/// PLC (Palette Line Color) and AMC (Palette Marker Color).
6/// When one of these options is given to `TGraph::Draw` the `TGraph` get its color
7/// from the current color palette defined by `gStyle->SetPalette(...)`. The color
8/// is determined according to the number of objects having palette coloring in
9/// the current pad.
10///
11/// In this example five graphs are displayed with palette coloring for lines and
12/// and filled area. The graphs are drawn with curves (`C` option) and one can see
13/// the color of each graph is picked inside the palette `kSolar`. The
14/// same is visible on filled polygons in the automatically built legend.
15/// To have more control on the legend, it can be created manually, see the graph
16/// tutorial gr111_legend.C
17///
18/// \macro_image
19/// \macro_code
20/// \author Olivier Couet
21
22void gr104_palettecolor () {
23
26
27 double x[5] = {1,2,3,4,5};
28 double y1[5] = {1.0,2.0,1.0,2.5,3.0};
29 double y2[5] = {1.1,2.1,1.1,2.6,3.1};
30 double y3[5] = {1.2,2.2,1.2,2.7,3.2};
31 double y4[5] = {1.3,2.3,1.3,2.8,3.3};
32 double y5[5] = {1.4,2.4,1.4,2.9,3.4};
33
34 TGraph *g1 = new TGraph(5,x,y1); g1->SetTitle("Graph with a red star");
35 TGraph *g2 = new TGraph(5,x,y2); g2->SetTitle("Graph with a circular marker");
36 TGraph *g3 = new TGraph(5,x,y3); g3->SetTitle("Graph with an open square marker");
37 TGraph *g4 = new TGraph(5,x,y4); g4->SetTitle("Graph with a blue star");
38 TGraph *g5 = new TGraph(5,x,y5); g5->SetTitle("Graph with a full square marker");
39
40 g1->SetLineWidth(3); g1->SetMarkerColor(kRed);
41 g2->SetLineWidth(3); g2->SetMarkerStyle(kCircle);
42 g3->SetLineWidth(3); g3->SetMarkerStyle(kOpenSquare);
43 g4->SetLineWidth(3); g4->SetMarkerColor(kBlue);
44 g5->SetLineWidth(3); g5->SetMarkerStyle(kFullSquare);
45
46 // The Draw option "A" (draw axes) is needed (only) for the first drawn graph
47 g1->Draw("CA* PLC PFC");
48 g2->Draw("PC PLC PFC");
49 g3->Draw("PC PLC PFC");
50 g4->Draw("*C PLC PFC");
51 g5->Draw("PC PLC PFC");
52
53 gPad->BuildLegend();
54}
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kOpenSquare
Definition TAttMarker.h:59
@ kCircle
Definition TAttMarker.h:56
@ kFullSquare
Definition TAttMarker.h:58
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kSolar
Definition TColor.h:133
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void SetOptTitle(Int_t tit=1)
Definition TStyle.h:338
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1890
Double_t x[n]
Definition legend1.C:17