{ "cells": [ { "cell_type": "markdown", "id": "d711e30d", "metadata": {}, "source": [ "# hist016_TH1_different_scales_canvas\n", "The second histogram is drawn in a transparent pad\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun \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": null, "id": "8d3ba6c1", "metadata": { "collapsed": false }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas(\"c1\", \"transparent pad\", 200, 10, 700, 500);\n", "TPad *pad1 = new TPad(\"pad1\", \"\", 0, 0, 1, 1);\n", "TPad *pad2 = new TPad(\"pad2\", \"\", 0, 0, 1, 1);\n", "pad2->SetFillStyle(4000); // will be transparent\n", "pad1->Draw();\n", "pad1->cd();\n", "\n", "TH1F *h1 = new TH1F(\"h1\", \"h1\", 100, -3, 3);\n", "TH1F *h2 = new TH1F(\"h2\", \"h2\", 100, -3, 3);\n", "TRandom r;\n", "for (Int_t i = 0; i < 100000; i++) {\n", " Double_t x1 = r.Gaus(-1, 0.5);\n", " Double_t x2 = r.Gaus(1, 1.5);\n", " if (i < 1000)\n", " h1->Fill(x1);\n", " h2->Fill(x2);\n", "}\n", "h1->Draw();\n", "pad1->Update(); // this will force the generation of the \"stats\" box\n", "TPaveStats *ps1 = (TPaveStats *)h1->GetListOfFunctions()->FindObject(\"stats\");\n", "ps1->SetX1NDC(0.4);\n", "ps1->SetX2NDC(0.6);\n", "pad1->Modified();\n", "c1->cd();" ] }, { "cell_type": "markdown", "id": "4e019779", "metadata": {}, "source": [ "compute the pad range with suitable margins" ] }, { "cell_type": "code", "execution_count": null, "id": "c9c1d007", "metadata": { "collapsed": false }, "outputs": [], "source": [ "Double_t ymin = 0;\n", "Double_t ymax = 2000;\n", "Double_t dy = (ymax - ymin) / 0.8; // 10 per cent margins top and bottom\n", "Double_t xmin = -3;\n", "Double_t xmax = 3;\n", "Double_t dx = (xmax - xmin) / 0.8; // 10 per cent margins left and right\n", "pad2->Range(xmin - 0.1 * dx, ymin - 0.1 * dy, xmax + 0.1 * dx, ymax + 0.1 * dy);\n", "pad2->Draw();\n", "pad2->cd();\n", "h2->SetLineColor(kRed);\n", "h2->Draw(\"][sames\");\n", "pad2->Update();\n", "TPaveStats *ps2 = (TPaveStats *)h2->GetListOfFunctions()->FindObject(\"stats\");\n", "ps2->SetX1NDC(0.65);\n", "ps2->SetX2NDC(0.85);\n", "ps2->SetTextColor(kRed);" ] }, { "cell_type": "markdown", "id": "481d1756", "metadata": {}, "source": [ "draw axis on the right side of the pad" ] }, { "cell_type": "code", "execution_count": null, "id": "5466443b", "metadata": { "collapsed": false }, "outputs": [], "source": [ "TGaxis *axis = new TGaxis(xmax, ymin, xmax, ymax, ymin, ymax, 50510, \"+L\");\n", "axis->SetLabelColor(kRed);\n", "axis->Draw();" ] }, { "cell_type": "markdown", "id": "fc77d238", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": null, "id": "f1cb8459", "metadata": { "collapsed": false }, "outputs": [], "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 }