{ "cells": [ { "cell_type": "markdown", "id": "475f147e", "metadata": {}, "source": [ "# perceptualcolormap\n", "\n", "On geographical plot this fixed point can, for instance, the \"sea level\". A perceptual\n", "colormap provides a monotonic luminance variations above and below this fixed value.\n", "Unlike the rainbow colormap, this colormap provides a faithful representation of the\n", "structures in the data.\n", "\n", "This macro demonstrates how to produce the perceptual colormap shown on the figure 2\n", "in [this article](https://root.cern/blog/rainbow-color-map/).\n", "\n", "The function `Perceptual_Colormap` takes two parameters as input:\n", " 1. `h`, the `TH2D` to be drawn\n", " 2. `val_cut`, the Z value defining the \"sea level\"\n", "\n", "Having these parameters this function defines two color maps: one above `val_cut` and one\n", "below.\n", "\n", "\n", "\n", "\n", "**Author:** Olivier Couet \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:37 PM." ] }, { "cell_type": "markdown", "id": "87a00fe7", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 1, "id": "8512cc11", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:20.912980Z", "iopub.status.busy": "2026-05-19T20:37:20.912861Z", "iopub.status.idle": "2026-05-19T20:37:20.919502Z", "shell.execute_reply": "2026-05-19T20:37:20.919091Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "\n", "void Perceptual_Colormap(TH2D *h, Double_t val_cut)\n", "{\n", " Double_t max = h->GetMaximum(); // Histogram's maximum\n", " Double_t min = h->GetMinimum(); // Histogram's minimum\n", " Double_t per_cut = (val_cut - min) / (max - min); // normalized value of val_cut\n", " Double_t eps = (max - min) * 0.00001; // epsilon\n", "\n", " // Definition of the two palettes below and above val_cut\n", " const Int_t Number = 4;\n", " Double_t Red[Number] = {0.11, 0.19, 0.30, 0.89};\n", " Double_t Green[Number] = {0.03, 0.304, 0.60, 0.91};\n", " Double_t Blue[Number] = {0.18, 0.827, 0.50, 0.70};\n", " Double_t Stops[Number] = {0., per_cut, per_cut + eps, 1.};\n", "\n", " Int_t nb = 256;\n", " h->SetContour(nb);\n", "\n", " TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, nb);\n", "\n", " // Histogram drawing\n", " h->Draw(\"colz\");\n", "}" ] }, { "cell_type": "code", "execution_count": 2, "id": "8693cc42", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:20.920822Z", "iopub.status.busy": "2026-05-19T20:37:20.920697Z", "iopub.status.idle": "2026-05-19T20:37:21.543395Z", "shell.execute_reply": "2026-05-19T20:37:21.542887Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "TH2D *h = new TH2D(\"h\", \"Perceptual Colormap\", 200, -4, 4, 200, -4, 4);\n", "h->SetStats(0);\n", "\n", "Double_t a, b;\n", "for (Int_t i = 0; i < 1000000; i++) {\n", " gRandom->Rannor(a, b);\n", " h->Fill(a - 1.5, b - 1.5, 0.1);\n", " h->Fill(a + 2., b - 3., 0.07);\n", " h->Fill(a - 3., b + 3., 0.05);\n", " gRandom->Rannor(a, b);\n", " h->Fill(a + 1.5, b + 1.5, -0.08);\n", "}\n", "Perceptual_Colormap(h, 0.);" ] }, { "cell_type": "markdown", "id": "5bee7538", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 3, "id": "2b62faf5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:21.545109Z", "iopub.status.busy": "2026-05-19T20:37:21.544981Z", "iopub.status.idle": "2026-05-19T20:37:21.866663Z", "shell.execute_reply": "2026-05-19T20:37:21.865857Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }