{ "cells": [ { "cell_type": "markdown", "id": "f7777eff", "metadata": {}, "source": [ "# canvas\n", "One of the first actions in a ROOT session is the creation of a Canvas.\n", "Here we create a Canvas named \"c1\".\n", "\n", "After having executed this macro, try now to point on any object on the\n", "screen: pad, text, lines, etc.\n", "\n", "When the cursor points to sensitive areas in an object, the cursor\n", "shape changes and suggests the type of action that can be applied.\n", "\n", "For example:\n", " - One can move, grow,shrink a pad.\n", " - A text can be moved.\n", " - A line can be moved or its end points can be modified.\n", " - One can move, grow and shrink PaveLabels and PavesText.\n", "\n", "Point to an object and click the right mouse button to change attributes.\n", "Try to change the canvas size.\n", "\n", "In the canvas \"File\" menu, select the option \"Print\" to produce\n", "a PostScript file with a copy of the canvas.\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:36 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "98420b6c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:49.703822Z", "iopub.status.busy": "2026-05-19T20:36:49.703708Z", "iopub.status.idle": "2026-05-19T20:36:50.047890Z", "shell.execute_reply": "2026-05-19T20:36:50.047475Z" } }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas(\"c1\", \"Canvas Example\", 200, 10, 600, 480);\n", "\n", "gBenchmark->Start(\"canvas\");" ] }, { "cell_type": "markdown", "id": "d6e01a7c", "metadata": {}, "source": [ "Inside this canvas, we create two pads" ] }, { "cell_type": "code", "execution_count": 2, "id": "732428d3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:50.059094Z", "iopub.status.busy": "2026-05-19T20:36:50.058941Z", "iopub.status.idle": "2026-05-19T20:36:50.270389Z", "shell.execute_reply": "2026-05-19T20:36:50.269701Z" } }, "outputs": [], "source": [ "TPad *pad1 = new TPad(\"pad1\", \"This is pad1\", 0.05, 0.52, 0.95, 0.97);\n", "TPad *pad2 = new TPad(\"pad2\", \"This is pad2\", 0.05, 0.02, 0.95, 0.47);\n", "pad1->SetFillColor(11);\n", "pad2->SetFillColor(11);\n", "pad1->Draw();\n", "pad2->Draw();" ] }, { "cell_type": "markdown", "id": "8129edb8", "metadata": {}, "source": [ "A pad may contain other pads and graphics objects.\n", "We set the current pad to pad2.\n", "Note that the current pad is always highlighted." ] }, { "cell_type": "code", "execution_count": 3, "id": "cbcadd0e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:50.273224Z", "iopub.status.busy": "2026-05-19T20:36:50.273104Z", "iopub.status.idle": "2026-05-19T20:36:50.482240Z", "shell.execute_reply": "2026-05-19T20:36:50.481860Z" } }, "outputs": [], "source": [ "pad2->cd();\n", "TPad *pad21 = new TPad(\"pad21\", \"First subpad of pad2\", 0.02, 0.05, 0.48, 0.95, 17, 3);\n", "TPad *pad22 = new TPad(\"pad22\", \"Second subpad of pad2\", 0.52, 0.05, 0.98, 0.95, 17, 3);\n", "pad21->Draw();\n", "pad22->Draw();" ] }, { "cell_type": "markdown", "id": "aff28658", "metadata": {}, "source": [ "We enter some primitives in the created pads and set some attributes" ] }, { "cell_type": "code", "execution_count": 4, "id": "7ba3756a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:50.484565Z", "iopub.status.busy": "2026-05-19T20:36:50.484447Z", "iopub.status.idle": "2026-05-19T20:36:50.694007Z", "shell.execute_reply": "2026-05-19T20:36:50.693579Z" } }, "outputs": [], "source": [ "pad1->cd();\n", "float xt1 = 0.5;\n", "float yt1 = 0.1;\n", "TText *t1 = new TText(0.5, yt1, \"ROOT\");\n", "t1->SetTextAlign(22);\n", "t1->SetTextSize(0.05);\n", "t1->Draw();\n", "TLine *line1 = new TLine(0.05, 0.05, 0.80, 0.70);\n", "line1->SetLineWidth(8);\n", "line1->SetLineColor(2);\n", "line1->Draw();\n", "line1->DrawLine(0.6, 0.1, 0.9, 0.9);\n", "TLine *line2 = new TLine(0.05, 0.70, 0.50, 0.10);\n", "line2->SetLineWidth(4);\n", "line2->SetLineColor(5);\n", "line2->Draw();\n", "\n", "pad21->cd();\n", "TText *t21 = new TText(0.05, 0.8, \"This is pad21\");\n", "t21->SetTextSize(0.1);\n", "t21->Draw();\n", "float xp2 = 0.5;\n", "float yp2 = 0.4;\n", "TPavesText *paves = new TPavesText(0.1, 0.1, xp2, yp2);\n", "paves->AddText(\"This is a PavesText\");\n", "paves->AddText(\"You can add new lines\");\n", "paves->AddText(\"Text formatting is automatic\");\n", "paves->SetFillColor(43);\n", "paves->Draw();\n", "pad22->cd();\n", "TText *t22 = new TText(0.05, 0.8, \"This is pad22\");\n", "t22->SetTextSize(0.1);\n", "t22->Draw();\n", "float xlc = 0.01;\n", "float ylc = 0.01;\n", "TPaveLabel *label = new TPaveLabel(xlc, ylc, xlc + 0.8, ylc + 0.1, \"This is a PaveLabel\");\n", "label->SetFillColor(24);\n", "label->Draw();" ] }, { "cell_type": "markdown", "id": "c287f9ff", "metadata": {}, "source": [ "Modify object attributes in a loop" ] }, { "cell_type": "code", "execution_count": 5, "id": "3e1c6110", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:50.695738Z", "iopub.status.busy": "2026-05-19T20:36:50.695593Z", "iopub.status.idle": "2026-05-19T20:36:50.902295Z", "shell.execute_reply": "2026-05-19T20:36:50.901635Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "