Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
perceptualcolormap.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// A “Perceptual” colormap explicitly identifies a fixed value in the data
5///
6/// On geographical plot this fixed point can, for instance, the "sea level". A perceptual
7/// colormap provides a monotonic luminance variations above and below this fixed value.
8/// Unlike the rainbow colormap, this colormap provides a faithful representation of the
9/// structures in the data.
10///
11/// This macro demonstrates how to produce the perceptual colormap shown on the figure 2
12/// in [this article](https://root.cern/blog/rainbow-color-map/).
13///
14/// The function `Perceptual_Colormap` takes two parameters as input:
15/// 1. `h`, the `TH2D` to be drawn
16/// 2. `val_cut`, the Z value defining the "sea level"
17///
18/// Having these parameters this function defines two color maps: one above `val_cut` and one
19/// below.
20///
21/// \macro_image
22/// \macro_code
23///
24/// \author Olivier Couet
25
26void Perceptual_Colormap(TH2D *h, Double_t val_cut)
27{
28 Double_t max = h->GetMaximum(); // Histogram's maximum
29 Double_t min = h->GetMinimum(); // Histogram's minimum
30 Double_t per_cut = (val_cut - min) / (max - min); // normalized value of val_cut
31 Double_t eps = (max - min) * 0.00001; // epsilon
32
33 // Definition of the two palettes below and above val_cut
34 const Int_t Number = 4;
35 Double_t Red[Number] = {0.11, 0.19, 0.30, 0.89};
36 Double_t Green[Number] = {0.03, 0.304, 0.60, 0.91};
37 Double_t Blue[Number] = {0.18, 0.827, 0.50, 0.70};
38 Double_t Stops[Number] = {0., per_cut, per_cut + eps, 1.};
39
40 Int_t nb = 256;
41 h->SetContour(nb);
42
43 TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, nb);
44
45 // Histogram drawing
46 h->Draw("colz");
47}
48
49void perceptualcolormap()
50{
51 TH2D *h = new TH2D("h", "Perceptual Colormap", 200, -4, 4, 200, -4, 4);
52 h->SetStats(0);
53
54 Double_t a, b;
55 for (Int_t i = 0; i < 1000000; i++) {
56 gRandom->Rannor(a, b);
57 h->Fill(a - 1.5, b - 1.5, 0.1);
58 h->Fill(a + 2., b - 3., 0.07);
59 h->Fill(a - 3., b + 3., 0.05);
60 gRandom->Rannor(a, b);
61 h->Fill(a + 1.5, b + 1.5, -0.08);
62 }
63 Perceptual_Colormap(h, 0.);
64}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
static Int_t CreateGradientColorTable(UInt_t Number, Double_t *Stops, Double_t *Red, Double_t *Green, Double_t *Blue, UInt_t NColors, Float_t alpha=1., Bool_t setPalette=kTRUE)
Static function creating a color table with several connected linear gradients.
Definition TColor.cxx:2731
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:358
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:507
__device__ AFloat max(AFloat x, AFloat y)
Definition Kernels.cuh:207