{ "cells": [ { "cell_type": "markdown", "id": "85a2c8b0", "metadata": {}, "source": [ "# hist011_TH1_legend_autoplaced\n", "found at painting time.\n", "\n", "The following example illustrate this facility. Only the width and height of the\n", "legend is specified in percentage of the pad size.\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": "dce431d7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:10.223290Z", "iopub.status.busy": "2026-05-19T20:12:10.223179Z", "iopub.status.idle": "2026-05-19T20:12:10.585051Z", "shell.execute_reply": "2026-05-19T20:12:10.584462Z" } }, "outputs": [], "source": [ "auto *c4 = new TCanvas(\"c\", \"c\", 600, 500);" ] }, { "cell_type": "markdown", "id": "6a51110d", "metadata": {}, "source": [ "Create a dummy histogram" ] }, { "cell_type": "code", "execution_count": 2, "id": "b7190f68", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:10.587431Z", "iopub.status.busy": "2026-05-19T20:12:10.587312Z", "iopub.status.idle": "2026-05-19T20:12:10.803971Z", "shell.execute_reply": "2026-05-19T20:12:10.798657Z" } }, "outputs": [], "source": [ "auto *hpx = new TH1D(\"hpx\", \"This is the hpx distribution\", 100, -4., 4.);\n", "hpx->FillRandom(\"gaus\", 50000);\n", "hpx->Draw(\"E\");\n", "hpx->GetYaxis()->SetTitle(\"Y Axis title\");\n", "hpx->GetYaxis()->SetTitleOffset(1.3);\n", "hpx->GetYaxis()->CenterTitle(true);\n", "hpx->GetXaxis()->SetTitle(\"X Axis title\");\n", "hpx->GetXaxis()->CenterTitle(true);" ] }, { "cell_type": "markdown", "id": "1274f6a7", "metadata": {}, "source": [ "Create another dummy histogram" ] }, { "cell_type": "code", "execution_count": 3, "id": "e89d49a1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:10.815096Z", "iopub.status.busy": "2026-05-19T20:12:10.814941Z", "iopub.status.idle": "2026-05-19T20:12:11.031293Z", "shell.execute_reply": "2026-05-19T20:12:11.030483Z" } }, "outputs": [], "source": [ "auto *h1 = new TH1D(\"h1\", \"A green histogram\", 100, -2., 2.);\n", "h1->FillRandom(\"gaus\", 10000);\n", "h1->SetLineColor(kGreen);\n", "h1->Draw(\"same\");" ] }, { "cell_type": "markdown", "id": "906156b3", "metadata": {}, "source": [ "Create a dummy graph" ] }, { "cell_type": "code", "execution_count": 4, "id": "04152b44", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:11.033339Z", "iopub.status.busy": "2026-05-19T20:12:11.033217Z", "iopub.status.idle": "2026-05-19T20:12:11.237346Z", "shell.execute_reply": "2026-05-19T20:12:11.236745Z" } }, "outputs": [], "source": [ "auto *g = new TGraph();\n", "g->SetPoint(0, -3.5, 100);\n", "g->SetPoint(1, -3.0, 300);\n", "g->SetPoint(2, -2.0, 1000);\n", "g->SetPoint(3, 1.0, 800);\n", "g->SetPoint(4, 0.0, 200);\n", "g->SetPoint(5, 3.0, 200);\n", "g->SetPoint(6, 3.0, 700);\n", "g->Draw(\"L\");\n", "g->SetTitle(\"This is a TGraph\");\n", "g->SetLineColor(kRed);\n", "g->SetFillColor(0);" ] }, { "cell_type": "markdown", "id": "e75ece1a", "metadata": {}, "source": [ "TPad::BuildLegend() default placement values are such that they trigger\n", "the automatic placement." ] }, { "cell_type": "code", "execution_count": 5, "id": "09d1dfae", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:11.239708Z", "iopub.status.busy": "2026-05-19T20:12:11.239557Z", "iopub.status.idle": "2026-05-19T20:12:11.445181Z", "shell.execute_reply": "2026-05-19T20:12:11.444575Z" } }, "outputs": [], "source": [ "c4->BuildLegend();" ] }, { "cell_type": "markdown", "id": "d61b55fd", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "cd2480a4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:12:11.447020Z", "iopub.status.busy": "2026-05-19T20:12:11.446897Z", "iopub.status.idle": "2026-05-19T20:12:11.652140Z", "shell.execute_reply": "2026-05-19T20:12:11.651598Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "