{ "cells": [ { "cell_type": "markdown", "id": "d87a3c7e", "metadata": {}, "source": [ "# gr111_legend\n", "\n", "\n", "\n", "**Author:** Emanuele Chiamulera \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:38 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "7d218013", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:28.384868Z", "iopub.status.busy": "2026-05-19T20:38:28.384750Z", "iopub.status.idle": "2026-05-19T20:38:28.734957Z", "shell.execute_reply": "2026-05-19T20:38:28.734282Z" } }, "outputs": [], "source": [ "auto c = new TCanvas(\"c\",\"\", 900, 800);\n", "c->SetGrid();\n", "\n", "const Int_t n = 5;\n", "Double_t x[n] = {-3.00, -2.68, -2.36, -2.05, -1.73};\n", "Double_t y1[n] = {-0.98, -0.89, -0.71, -0.46, -0.16};\n", "Double_t y2[n] = {-2.98, -2.89, -2.71, -2.46, -2.16};\n", "\n", "\n", "TGraph *gr1 = new TGraph(n, x, y1); //Create the graph\n", "gr1->SetLineColor(2);\n", "gr1->SetLineWidth(4);\n", "gr1->SetMarkerColor(4);\n", "gr1->SetMarkerStyle(21);\n", "gr1->SetTitle(\"Graph with legend\");\n", "\n", "TLegend *legend = new TLegend(0.1,0.7,0.38,0.9); //Create the TLegend object and define it's position \n", "legend->SetHeader(\"Legend title\", \"C\"); //\"C\" Center alignment for the header (\"L\" Left and \"R\" Right)\n", "legend->SetFillColor(kWhite);\n", "legend->SetBorderSize(1);\n", "legend->SetTextSize(0.04);\n", "legend->AddEntry(gr1, \"Data points\", \"lp\"); // \"p\" for point marker, \"l\" for line, \"e\" for error bars if TGraphError is used.\n", "\n", "gr1->Draw(\"\");" ] }, { "cell_type": "markdown", "id": "307430a2", "metadata": {}, "source": [ "Draw the legend" ] }, { "cell_type": "code", "execution_count": 2, "id": "dbc87f62", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:28.747643Z", "iopub.status.busy": "2026-05-19T20:38:28.747476Z", "iopub.status.idle": "2026-05-19T20:38:28.985820Z", "shell.execute_reply": "2026-05-19T20:38:28.985236Z" } }, "outputs": [], "source": [ "legend->Draw();" ] }, { "cell_type": "markdown", "id": "9a90b32d", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 3, "id": "1ddb9994", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:28.987536Z", "iopub.status.busy": "2026-05-19T20:38:28.987423Z", "iopub.status.idle": "2026-05-19T20:38:29.199056Z", "shell.execute_reply": "2026-05-19T20:38:29.198575Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "