{ "cells": [ { "cell_type": "markdown", "id": "7770bd9c", "metadata": {}, "source": [ "# palettes\n", "It generates a png file for each palette and one pdf file, with a table of\n", "content, containing all the palettes.\n", "\n", "In ROOT, [more than 60 high quality palettes are predefined with 255 colors\n", "each](https://root.cern/doc/master/classTColor.html#C06).\n", "\n", "These palettes can be accessed \"by name\" with `gStyle->SetPalette(num)`. num\n", "can be taken within the enum given in the previous link. As an example\n", "`gStyle->SetPalette(kCividis)` will select the following palette.\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": "code", "execution_count": 1, "id": "6d24bf2a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:20.013340Z", "iopub.status.busy": "2026-05-19T20:37:20.013199Z", "iopub.status.idle": "2026-05-19T20:37:20.378407Z", "shell.execute_reply": "2026-05-19T20:37:20.377703Z" } }, "outputs": [], "source": [ "TCanvas *c = nullptr;" ] }, { "cell_type": "markdown", "id": "836a3c9f", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 2, "id": "cf09c959", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:20.381346Z", "iopub.status.busy": "2026-05-19T20:37:20.381214Z", "iopub.status.idle": "2026-05-19T20:37:20.401101Z", "shell.execute_reply": "2026-05-19T20:37:20.400377Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void draw_palette(int p, TString n)\n", "{\n", " delete c;\n", " c = new TCanvas(\"c\", \"Contours\", 0, 0, 500, 500);\n", " 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);\n", " f2->SetContour(99);\n", " gStyle->SetPalette(p);\n", " f2->SetLineWidth(1);\n", " f2->SetLineColor(kBlack);\n", " f2->Draw(\"surf1z\");\n", "\n", " // Title\n", " TPaveText *pt = new TPaveText(10, 11, 10, 11, \"blNDC\");\n", " pt->SetName(\"title\");\n", " pt->Draw();\n", " TString num = n;\n", " num.ReplaceAll(\" \", \"\");\n", " TLatex *l = new TLatex(-0.8704441, 0.9779387,\n", " TString::Format(\"Palette #%d: %s #scale[0.7]{(#font[82]{k%s})}\", p, n.Data(), num.Data()));\n", " l->SetTextFont(42);\n", " l->SetTextSize(0.035);\n", " l->Draw();\n", " c->Update();\n", " c->Print(TString::Format(\"palette_%d.png\", p));\n", "\n", " TString opt = TString(\"Title:\") + n;\n", " if (p == kDeepSea)\n", " c->Print(\"palettes.pdf(\", opt.Data());\n", " else if (p == kCividis)\n", " c->Print(\"palettes.pdf)\", opt.Data());\n", " else\n", " c->Print(\"palettes.pdf\", opt.Data());\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "id": "cf88aa7d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:20.402710Z", "iopub.status.busy": "2026-05-19T20:37:20.402559Z", "iopub.status.idle": "2026-05-19T20:37:28.588356Z", "shell.execute_reply": "2026-05-19T20:37:28.587846Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "