Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
palettes.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// This macro draws all the high definition palettes available in ROOT.
5/// It generates a png file for each palette and one pdf file, with a table of
6/// content, containing all the palettes.
7///
8/// In ROOT, [more than 60 high quality palettes are predefined with 255 colors each](https://root.cern/doc/master/classTColor.html#C06).
9///
10/// These palettes can be accessed "by name" with `gStyle->SetPalette(num)`. num
11/// can be taken within the enum given in the previous link. As an example
12/// `gStyle->SetPalette(kCividis)` will select the following palette.
13///
14/// \macro_image
15/// \macro_code
16///
17/// \author Olivier Couet
18
19TCanvas *c = nullptr;
20
21void draw_palette(int p, TString n)
22{
23 delete c;
24 c = new TCanvas("c","Contours",0,0,500,500);
25 TF2 *f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",0.999,3.002,0.999,3.002);
26 f2->SetContour(99);
28 f2->SetLineWidth(1);
30 f2->Draw("surf1z");
31
32 // Title
33 TPaveText *pt = new TPaveText(10,11,10,11,"blNDC");
34 pt->SetName("title");
35 pt->Draw();
36 TString num = n;
37 num.ReplaceAll(" ","");
38 TLatex *l = new TLatex(-0.8704441,0.9779387,TString::Format("Palette #%d: %s #scale[0.7]{(#font[82]{k%s})}",p,n.Data(),num.Data()));
39 l->SetTextFont(42);
40 l->SetTextSize(0.035);
41 l->Draw();
42 c->Update();
43 c->Print(TString::Format("palette_%d.png", p));
44
45 TString opt = TString("Title:") + n;
46 if (p == kDeepSea)
47 c->Print("palettes.pdf(", opt.Data());
48 else if (p == kCividis)
49 c->Print("palettes.pdf)", opt.Data());
50 else
51 c->Print("palettes.pdf", opt.Data());
52}
53
54void palettes()
55{
56 gROOT->SetBatch(1);
57 draw_palette(kDeepSea, "Deap Sea");
58 draw_palette(kGreyScale, "Grey Scale");
59 draw_palette(kDarkBodyRadiator, "Dark Body Radiator");
60 draw_palette(kBlueYellow, "Blue Yellow");
61 draw_palette(kRainBow, "Rain Bow");
62 draw_palette(kInvertedDarkBodyRadiator, "Inverted Dark Body Radiator");
63 draw_palette(kBird, "Bird");
64 draw_palette(kCubehelix, "Cube helix");
65 draw_palette(kGreenRedViolet, "Green Red Violet");
66 draw_palette(kBlueRedYellow, "Blue Red Yellow");
67 draw_palette(kOcean, "Ocean");
68 draw_palette(kColorPrintableOnGrey, "Color Printable On Grey");
69 draw_palette(kAlpine, "Alpine");
70 draw_palette(kAquamarine, "Aquamarine");
71 draw_palette(kArmy, "Army");
72 draw_palette(kAtlantic, "Atlantic");
73 draw_palette(kAurora, "Aurora");
74 draw_palette(kAvocado, "Avocado");
75 draw_palette(kBeach, "Beach");
76 draw_palette(kBlackBody, "Black Body");
77 draw_palette(kBlueGreenYellow, "Blue Green Yellow");
78 draw_palette(kBrownCyan, "Brown Cyan");
79 draw_palette(kCMYK, "CMYK");
80 draw_palette(kCandy, "Candy");
81 draw_palette(kCherry, "Cherry");
82 draw_palette(kCoffee, "Coffee");
83 draw_palette(kDarkRainBow, "Dark Rain Bow");
84 draw_palette(kDarkTerrain, "Dark Terrain");
85 draw_palette(kFall, "Fall");
86 draw_palette(kFruitPunch, "Fruit Punch");
87 draw_palette(kFuchsia, "Fuchsia");
88 draw_palette(kGreyYellow, "Grey Yellow");
89 draw_palette(kGreenBrownTerrain, "Green Brown Terrain");
90 draw_palette(kGreenPink, "Green Pink");
91 draw_palette(kIsland, "Island");
92 draw_palette(kLake, "Lake");
93 draw_palette(kLightTemperature, "Light Temperature");
94 draw_palette(kLightTerrain, "Light Terrain");
95 draw_palette(kMint, "Mint");
96 draw_palette(kNeon, "Neon");
97 draw_palette(kPastel, "Pastel");
98 draw_palette(kPearl, "Pearl");
99 draw_palette(kPigeon, "Pigeon");
100 draw_palette(kPlum, "Plum");
101 draw_palette(kRedBlue, "Red Blue");
102 draw_palette(kRose, "Rose");
103 draw_palette(kRust, "Rust");
104 draw_palette(kSandyTerrain, "Sandy Terrain");
105 draw_palette(kSienna, "Sienna");
106 draw_palette(kSolar, "Solar");
107 draw_palette(kSouthWest, "South West");
108 draw_palette(kStarryNight, "Starry Night");
109 draw_palette(kSunset, "Sunset");
110 draw_palette(kTemperatureMap, "Temperature Map");
111 draw_palette(kThermometer, "Thermometer");
112 draw_palette(kValentine, "Valentine");
113 draw_palette(kVisibleSpectrum, "Visible Spectrum");
114 draw_palette(kWaterMelon, "Water Melon");
115 draw_palette(kCool, "Cool");
116 draw_palette(kCopper, "Copper");
117 draw_palette(kGistEarth, "Gist Earth");
118 draw_palette(kViridis, "Viridis");
119 draw_palette(kCividis, "Cividis");
120}
121
#define c(i)
Definition RSha256.hxx:101
@ kBlack
Definition Rtypes.h:65
@ kFall
Definition TColor.h:123
@ kStarryNight
Definition TColor.h:131
@ kAtlantic
Definition TColor.h:119
@ kIsland
Definition TColor.h:125
@ kBlackBody
Definition TColor.h:120
@ kFruitPunch
Definition TColor.h:123
@ kArmy
Definition TColor.h:118
@ kAurora
Definition TColor.h:119
@ kBrownCyan
Definition TColor.h:121
@ kBeach
Definition TColor.h:120
@ kAquamarine
Definition TColor.h:118
@ kPastel
Definition TColor.h:127
@ kCubehelix
Definition TColor.h:116
@ kAvocado
Definition TColor.h:119
@ kGreenRedViolet
Definition TColor.h:116
@ kAlpine
Definition TColor.h:118
@ kVisibleSpectrum
Definition TColor.h:132
@ kCMYK
Definition TColor.h:121
@ kInvertedDarkBodyRadiator
Definition TColor.h:115
@ kWaterMelon
Definition TColor.h:133
@ kOcean
Definition TColor.h:117
@ kDarkBodyRadiator
Definition TColor.h:114
@ kDarkTerrain
Definition TColor.h:123
@ kLightTemperature
Definition TColor.h:126
@ kRust
Definition TColor.h:129
@ kCopper
Definition TColor.h:133
@ kTemperatureMap
Definition TColor.h:131
@ kSolar
Definition TColor.h:130
@ kRedBlue
Definition TColor.h:128
@ kDeepSea
Definition TColor.h:114
@ kRainBow
Definition TColor.h:115
@ kSouthWest
Definition TColor.h:130
@ kPlum
Definition TColor.h:128
@ kGreenBrownTerrain
Definition TColor.h:124
@ kGreyYellow
Definition TColor.h:124
@ kGreyScale
Definition TColor.h:114
@ kRose
Definition TColor.h:129
@ kSunset
Definition TColor.h:131
@ kCoffee
Definition TColor.h:122
@ kGreenPink
Definition TColor.h:125
@ kColorPrintableOnGrey
Definition TColor.h:117
@ kSienna
Definition TColor.h:130
@ kBlueYellow
Definition TColor.h:115
@ kBlueRedYellow
Definition TColor.h:117
@ kValentine
Definition TColor.h:132
@ kSandyTerrain
Definition TColor.h:129
@ kDarkRainBow
Definition TColor.h:122
@ kViridis
Definition TColor.h:134
@ kCandy
Definition TColor.h:121
@ kCherry
Definition TColor.h:122
@ kNeon
Definition TColor.h:127
@ kBird
Definition TColor.h:116
@ kFuchsia
Definition TColor.h:124
@ kBlueGreenYellow
Definition TColor.h:120
@ kPearl
Definition TColor.h:127
@ kPigeon
Definition TColor.h:128
@ kCividis
Definition TColor.h:134
@ kCool
Definition TColor.h:133
@ kLake
Definition TColor.h:125
@ kMint
Definition TColor.h:126
@ kGistEarth
Definition TColor.h:134
@ kThermometer
Definition TColor.h:132
@ kLightTerrain
Definition TColor.h:126
winID h TVirtualViewer3D TVirtualGLPainter p
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
A 2-Dim function with parameters.
Definition TF2.h:29
virtual void SetContour(Int_t nlevels=20, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition TF2.cxx:892
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF2.cxx:259
To draw Mathematical Formula.
Definition TLatex.h:18
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
virtual void SetName(const char *name="")
Definition TPave.h:79
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1884
TPaveText * pt
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4