Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example showing how to produce a perceptual palette #6314

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions tutorials/graphics/perceptualcolormap.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/// \file
/// \ingroup tutorial_graphics
/// \notebook
/// A “Perceptual” colormap explicitly identifies a fixed value in the data
////
/// On geographical plot this fixed point can be seen as the "sea level", and provides
/// monotonic luminance variations above and below this fixed value. Unlike the rainbow
/// colormap, this colormap provides a faithful representation of the structures in the
/// data.
///
/// This macro demonstrates how to produce the perceptual colormap shown on the figure 2
/// in [this article](https://root.cern/blog/rainbow-color-map/).
///
/// The function `Perceptual_Colormap` take two parameters as input:
/// 1. `h`, the `TH2D` to be drawn
/// 2. `val_cut`, the Z value defining the "sea level"
///
/// Having these parameters this function defines two color maps: one above `val_cut` and one
/// below.
////
/// \macro_image
/// \macro_code
///
/// \author Olivier Couet

void Perceptual_Colormap(TH2D *h, Double_t val_cut) {
Double_t max = h->GetMaximum(); // Histogram's maximum
Double_t min = h->GetMinimum(); // Histogram's minimum
Double_t per_cut = (val_cut-min)/(max-min); // normalized value of val_cut
Double_t eps = (max-min)*0.00001; // epsilon

// Definition of the two palettes below and above val_cut
const Int_t Number = 4;
Double_t Red[Number] = { 0.11, 0.19 , 0.30, 0.89};
Double_t Green[Number] = { 0.03, 0.304, 0.60, 0.91};
Double_t Blue[Number] = { 0.18, 0.827, 0.50, 0.70};
Double_t Stops[Number] = { 0., per_cut, per_cut+eps, 1. };

Int_t nb= 256;
h->SetContour(nb);

TColor::CreateGradientColorTable(Number,Stops,Red,Green,Blue,nb);

// Histogram drawaing
h->Draw("colz");
}

void perceptualcolormap() {
TH2D *h = new TH2D("h","Perceptual Colormap",200,-4,4,200,-4,4);
h->SetStats(0);

Double_t a,b,c;
for (Int_t i=0;i<1000000;i++) {
c = gRandom->Rndm();
gRandom->Rannor(a,b);
h->Fill(a-1.5,b-1.5,0.1);
h->Fill(a+2.,b-3.,0.07);
h->Fill(a-3.,b+3.,0.05);
gRandom->Rannor(a,b);
h->Fill(a+1.5,b+1.5,-0.08);
}
Perceptual_Colormap(h, 0.);
}