{ "cells": [ { "cell_type": "markdown", "id": "d0008e72", "metadata": {}, "source": [ "# gr202_textmarkers\n", "The text is drawn in a TExec function attached to the TGraph,\n", "therefore if the a graph's point is\n", "moved interactively, the text will be automatically updated.\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:38 PM." ] }, { "cell_type": "markdown", "id": "4d2d9abf", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 1, "id": "73168acc", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:33.680261Z", "iopub.status.busy": "2026-05-19T20:38:33.680153Z", "iopub.status.idle": "2026-05-19T20:38:33.690754Z", "shell.execute_reply": "2026-05-19T20:38:33.690192Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void drawtext()\n", "{\n", " Int_t i,n;\n", " Double_t x,y;\n", " TLatex l;\n", "\n", " l.SetTextSize(0.025);\n", " l.SetTextFont(42);\n", " l.SetTextAlign(21);\n", " l.SetTextColor(kBlue);\n", "\n", " auto g = (TGraph*)gPad->GetListOfPrimitives()->FindObject(\"Graph\");\n", " n = g->GetN();\n", "\n", " for (i=0; iGetPoint(i,x,y);\n", " l.PaintText(x,y+0.2,Form(\"(%4.2f,%4.2f)\",x,y));\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 2, "id": "37091650", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:33.692344Z", "iopub.status.busy": "2026-05-19T20:38:33.692219Z", "iopub.status.idle": "2026-05-19T20:38:34.006204Z", "shell.execute_reply": "2026-05-19T20:38:34.005641Z" } }, "outputs": [], "source": [ "TCanvas *c = new TCanvas(\"c\",\"A Simple Graph Example with Text\",700,500);\n", "c->SetGrid();\n", "\n", "const Int_t n = 10;\n", "auto gr = new TGraph(n);\n", "gr->SetTitle(\"A Simple Graph Example with Text\");\n", "gr->SetMarkerStyle(20);\n", "auto ex = new TExec(\"ex\",\"drawtext();\");\n", "gr->GetListOfFunctions()->Add(ex);\n", "\n", "Double_t x, y;\n", "for (Int_t i=0;iSetPoint(i,x,y);\n", "}\n", "gr->Draw(\"ALP\");" ] }, { "cell_type": "markdown", "id": "7e77662f", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 3, "id": "5319e00e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:34.008083Z", "iopub.status.busy": "2026-05-19T20:38:34.007960Z", "iopub.status.idle": "2026-05-19T20:38:34.224240Z", "shell.execute_reply": "2026-05-19T20:38:34.223672Z" } }, "outputs": [ { "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 }