{ "cells": [ { "cell_type": "markdown", "id": "34c42ed6", "metadata": {}, "source": [ "# hist026_THStack_color_scheme\n", "In this example, the color scheme with six colors is used.\n", "It also shows that the grayscale version is an acceptable alternative.\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:12 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "98f8024c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:32.361445Z", "iopub.status.busy": "2026-05-19T20:12:32.361325Z", "iopub.status.idle": "2026-05-19T20:12:32.704853Z", "shell.execute_reply": "2026-05-19T20:12:32.704167Z" } }, "outputs": [], "source": [ "auto c1 = new TCanvas();\n", "auto hs = new THStack(\"hs\", \"Stacked 1D histograms colored using 6-colors scheme\");" ] }, { "cell_type": "markdown", "id": "a50c5065", "metadata": {}, "source": [ "Create six 1-d histograms and add them in the stack" ] }, { "cell_type": "code", "execution_count": 2, "id": "815502d7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:32.706925Z", "iopub.status.busy": "2026-05-19T20:12:32.706802Z", "iopub.status.idle": "2026-05-19T20:12:32.918122Z", "shell.execute_reply": "2026-05-19T20:12:32.917753Z" } }, "outputs": [], "source": [ "auto h1st = new TH1F(\"h1st\", \"A\", 100, -4, 4);\n", "h1st->FillRandom(\"gaus\", 20000);\n", "h1st->SetFillColor(kP6Blue);\n", "hs->Add(h1st);\n", "\n", "auto h2st = new TH1F(\"h2st\", \"B\", 100, -4, 4);\n", "h2st->FillRandom(\"gaus\", 15000);\n", "h2st->SetFillColor(kP6Yellow);\n", "hs->Add(h2st);\n", "\n", "auto h3st = new TH1F(\"h3st\", \"C\", 100, -4, 4);\n", "h3st->FillRandom(\"gaus\", 10000);\n", "h3st->SetFillColor(kP6Red);\n", "hs->Add(h3st);\n", "\n", "auto h4st = new TH1F(\"h4st\", \"D\", 100, -4, 4);\n", "h4st->FillRandom(\"gaus\", 10000);\n", "h4st->SetFillColor(kP6Grape);\n", "hs->Add(h4st);\n", "\n", "auto h5st = new TH1F(\"h5st\", \"E\", 100, -4, 4);\n", "h5st->FillRandom(\"gaus\", 10000);\n", "h5st->SetFillColor(kP6Gray);\n", "hs->Add(h5st);\n", "\n", "auto h6st = new TH1F(\"h6st\", \"F\", 100, -4, 4);\n", "h6st->FillRandom(\"gaus\", 10000);\n", "h6st->SetFillColor(kP6Violet);\n", "hs->Add(h6st);" ] }, { "cell_type": "markdown", "id": "c6aef18c", "metadata": {}, "source": [ "draw the stack with colors" ] }, { "cell_type": "code", "execution_count": 3, "id": "4b2d26bc", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:32.926356Z", "iopub.status.busy": "2026-05-19T20:12:32.926211Z", "iopub.status.idle": "2026-05-19T20:12:33.133062Z", "shell.execute_reply": "2026-05-19T20:12:33.132618Z" } }, "outputs": [], "source": [ "hs->Draw();\n", "TLegend *l = gPad->BuildLegend(.8, .55, 1., .9, \"\", \"F\");\n", "l->SetLineWidth(0);\n", "l->SetFillStyle(0);" ] }, { "cell_type": "markdown", "id": "59a527a5", "metadata": {}, "source": [ "draw the stack using gray-scale" ] }, { "cell_type": "code", "execution_count": 4, "id": "677fddb8", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:33.145395Z", "iopub.status.busy": "2026-05-19T20:12:33.145262Z", "iopub.status.idle": "2026-05-19T20:12:33.349412Z", "shell.execute_reply": "2026-05-19T20:12:33.348717Z" } }, "outputs": [], "source": [ "auto c2 = new TCanvas();\n", "c2->SetGrayscale();\n", "hs->Draw();\n", "l->Draw();" ] }, { "cell_type": "markdown", "id": "00da9c16", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "d4604b75", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:33.352566Z", "iopub.status.busy": "2026-05-19T20:12:33.352436Z", "iopub.status.idle": "2026-05-19T20:12:33.564166Z", "shell.execute_reply": "2026-05-19T20:12:33.563456Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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 }