{ "cells": [ { "cell_type": "markdown", "id": "287ae541", "metadata": {}, "source": [ "# hist005_TH1_palettecolor\n", "\n", "Palette coloring for histogram is activated thanks to the options `PFC`\n", "(Palette Fill Color), `PLC` (Palette Line Color) and `PMC` (Palette Marker Color).\n", "When one of these options is given to `TH1::Draw` the histogram gets its color\n", "from the current color palette defined by `gStyle->SetPalette(...)`. The color\n", "is determined according to the number of objects having palette coloring in\n", "the current pad.\n", "\n", "In this example five histograms are displayed with palette coloring for lines and\n", "and marker. The histograms are drawn with markers and error bars and one can see\n", "the color of each histogram is picked inside the default palette `kBird`.\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:11 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "df2ea869", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:55.179739Z", "iopub.status.busy": "2026-05-19T20:11:55.179597Z", "iopub.status.idle": "2026-05-19T20:11:55.550673Z", "shell.execute_reply": "2026-05-19T20:11:55.550268Z" } }, "outputs": [], "source": [ "auto *canvas = new TCanvas();" ] }, { "cell_type": "markdown", "id": "8805597f", "metadata": {}, "source": [ "Disable drawing the title of the canvas" ] }, { "cell_type": "code", "execution_count": 2, "id": "901705f9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:55.571104Z", "iopub.status.busy": "2026-05-19T20:11:55.570959Z", "iopub.status.idle": "2026-05-19T20:11:55.774793Z", "shell.execute_reply": "2026-05-19T20:11:55.774199Z" } }, "outputs": [], "source": [ "gStyle->SetOptTitle(kFALSE);" ] }, { "cell_type": "markdown", "id": "7a1a7147", "metadata": {}, "source": [ "Disable drawing the stats box" ] }, { "cell_type": "code", "execution_count": 3, "id": "0afc642a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:55.777023Z", "iopub.status.busy": "2026-05-19T20:11:55.776897Z", "iopub.status.idle": "2026-05-19T20:11:55.981067Z", "shell.execute_reply": "2026-05-19T20:11:55.980072Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gStyle->SetOptStat(0);\n", "\n", "auto *h1 = new TH1D(\"h1\", \"Histogram drawn with full circles\", 100, -4, 4);\n", "auto *h2 = new TH1D(\"h2\", \"Histogram drawn with full squares\", 100, -4, 4);\n", "auto *h3 = new TH1D(\"h3\", \"Histogram drawn with full triangles up\", 100, -4, 4);\n", "auto *h4 = new TH1D(\"h4\", \"Histogram drawn with full triangles down\", 100, -4, 4);\n", "auto *h5 = new TH1D(\"h5\", \"Histogram drawn with empty circles\", 100, -4, 4);" ] }, { "cell_type": "markdown", "id": "67226826", "metadata": {}, "source": [ "Use Mersenne-Twister random number generator" ] }, { "cell_type": "code", "execution_count": 4, "id": "e122e603", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:55.982704Z", "iopub.status.busy": "2026-05-19T20:11:55.982547Z", "iopub.status.idle": "2026-05-19T20:11:56.184863Z", "shell.execute_reply": "2026-05-19T20:11:56.184162Z" } }, "outputs": [], "source": [ "TRandom3 rng;\n", "for (int i = 0; i < 25000; i++) {\n", " // \"Rannor\" fills the two parameters we pass with RANdom numbers picked from a NORmal distribution.\n", " // In this case we ignore the second value.\n", " double val, ignored;\n", " rng.Rannor(val, ignored);\n", " // Fill() called with 2 arguments adds the given value (first arg) with the specified weight (second arg)\n", " h1->Fill(val, 10.);\n", " h2->Fill(val, 8.);\n", " h3->Fill(val, 6.);\n", " h4->Fill(val, 4.);\n", " h5->Fill(val, 2.);\n", "}" ] }, { "cell_type": "markdown", "id": "191a1243", "metadata": {}, "source": [ "Set different styles for the various histograms" ] }, { "cell_type": "code", "execution_count": 5, "id": "92b9225f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:56.186687Z", "iopub.status.busy": "2026-05-19T20:11:56.186528Z", "iopub.status.idle": "2026-05-19T20:11:56.390418Z", "shell.execute_reply": "2026-05-19T20:11:56.389877Z" } }, "outputs": [], "source": [ "h1->SetMarkerStyle(kFullCircle);\n", "h2->SetMarkerStyle(kFullSquare);\n", "h3->SetMarkerStyle(kFullTriangleUp);\n", "h4->SetMarkerStyle(kFullTriangleDown);\n", "h5->SetMarkerStyle(kOpenCircle);" ] }, { "cell_type": "markdown", "id": "3b66b47b", "metadata": {}, "source": [ "Draw all histograms overlapped in the same canvas (thanks to the \"SAME\" option)" ] }, { "cell_type": "code", "execution_count": 6, "id": "bc23c4c8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:56.392202Z", "iopub.status.busy": "2026-05-19T20:11:56.392079Z", "iopub.status.idle": "2026-05-19T20:11:56.595520Z", "shell.execute_reply": "2026-05-19T20:11:56.594968Z" } }, "outputs": [], "source": [ "h1->Draw(\"PLC PMC\");\n", "h2->Draw(\"SAME PLC PMC\");\n", "h3->Draw(\"SAME PLC PMC\");\n", "h4->Draw(\"SAME PLC PMC\");\n", "h5->Draw(\"SAME PLC PMC\");" ] }, { "cell_type": "markdown", "id": "4bd40aad", "metadata": {}, "source": [ "Build a legend from the objects drawn in the pad, using their description that we specified when constructing them" ] }, { "cell_type": "code", "execution_count": 7, "id": "466881c7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:56.597258Z", "iopub.status.busy": "2026-05-19T20:11:56.597137Z", "iopub.status.idle": "2026-05-19T20:11:56.800925Z", "shell.execute_reply": "2026-05-19T20:11:56.800244Z" } }, "outputs": [], "source": [ "gPad->BuildLegend();" ] }, { "cell_type": "markdown", "id": "fcb8da43", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 8, "id": "afa5c458", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:56.803134Z", "iopub.status.busy": "2026-05-19T20:11:56.803010Z", "iopub.status.idle": "2026-05-19T20:11:57.007629Z", "shell.execute_reply": "2026-05-19T20:11:57.006893Z" } }, "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 }