Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
graphpalettecolor.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// Palette coloring for graphs is activated thanks to the options `PFC` (Palette Fill
5 /// Color), `PLC` (Palette Line Color) and `AMC` (Palette Marker Color). When
6 /// 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 ///
16 /// \macro_image
17 /// \macro_code
18 ///
19 /// \author Olivier Couet
20 
21 void graphpalettecolor () {
22 
23  gStyle->SetOptTitle(kFALSE);
24  gStyle->SetPalette(kSolar);
25 
26  double x[5] = {1,2,3,4,5};
27  double y1[5] = {1.0,2.0,1.0,2.5,3.0};
28  double y2[5] = {1.1,2.1,1.1,2.6,3.1};
29  double y3[5] = {1.2,2.2,1.2,2.7,3.2};
30  double y4[5] = {1.3,2.3,1.3,2.8,3.3};
31  double y5[5] = {1.4,2.4,1.4,2.9,3.4};
32 
33  TGraph *g1 = new TGraph(5,x,y1); g1->SetTitle("Graph with a red star");
34  TGraph *g2 = new TGraph(5,x,y2); g2->SetTitle("Graph with a circular marker");
35  TGraph *g3 = new TGraph(5,x,y3); g3->SetTitle("Graph with an open square marker");
36  TGraph *g4 = new TGraph(5,x,y4); g4->SetTitle("Graph with a blue star");
37  TGraph *g5 = new TGraph(5,x,y5); g5->SetTitle("Graph with a full square marker");
38 
39  g1->SetLineWidth(3); g1->SetMarkerColor(kRed);
40  g2->SetLineWidth(3); g2->SetMarkerStyle(kCircle);
41  g3->SetLineWidth(3); g3->SetMarkerStyle(kOpenSquare);
42  g4->SetLineWidth(3); g4->SetMarkerColor(kBlue);
43  g5->SetLineWidth(3); g5->SetMarkerStyle(kFullSquare);
44 
45  g1->Draw("CA* PLC PFC");
46  g2->Draw("PC PLC PFC");
47  g3->Draw("PC PLC PFC");
48  g4->Draw("*C PLC PFC");
49  g5->Draw("PC PLC PFC");
50 
51  gPad->BuildLegend();
52 }