{ "cells": [ { "cell_type": "markdown", "id": "c0cb7354", "metadata": {}, "source": [ "# gr002_errors\n", "[gr03_err2gr.C](https://root.cern/doc/master/gerrors2_8C.html) tutorial\n", "\n", "See the [TGraphErrors documentation](https://root.cern/doc/master/classTGraphErrors.html)\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:37 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "1b95bc55", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:41.266091Z", "iopub.status.busy": "2026-05-19T20:37:41.265981Z", "iopub.status.idle": "2026-05-19T20:37:41.808053Z", "shell.execute_reply": "2026-05-19T20:37:41.797677Z" } }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas(\"c1\",\"A Simple Graph with error bars\",200,10,700,500);\n", "\n", "c1->SetGrid();\n", "c1->GetFrame()->SetBorderSize(12);" ] }, { "cell_type": "markdown", "id": "3941d342", "metadata": {}, "source": [ "We will use the constructor requiring: the number of points, arrays containing the x-and y-axis values, and arrays with the x- andy-axis errors" ] }, { "cell_type": "code", "execution_count": 2, "id": "f6d33209", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:41.828227Z", "iopub.status.busy": "2026-05-19T20:37:41.828088Z", "iopub.status.idle": "2026-05-19T20:37:42.053795Z", "shell.execute_reply": "2026-05-19T20:37:42.053385Z" } }, "outputs": [], "source": [ "const Int_t n = 10;\n", "Float_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};\n", "Float_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};\n", "Float_t ex[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};\n", "Float_t ey[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};" ] }, { "cell_type": "markdown", "id": "0db7d508", "metadata": {}, "source": [ "If all x-axis errors should zero, just provide a single 0 in place of ex" ] }, { "cell_type": "code", "execution_count": 3, "id": "df8b56e7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:42.067582Z", "iopub.status.busy": "2026-05-19T20:37:42.067449Z", "iopub.status.idle": "2026-05-19T20:37:42.282087Z", "shell.execute_reply": "2026-05-19T20:37:42.281706Z" } }, "outputs": [], "source": [ "TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey);\n", "\n", "gr->SetTitle(\"TGraphErrors Example\");\n", "gr->SetMarkerColor(4);\n", "gr->SetMarkerStyle(21);" ] }, { "cell_type": "markdown", "id": "cbeca193", "metadata": {}, "source": [ "To draw in a new/empty canvas or pad, include the option \"A\" so that the axes are drawn (leave it out if the graph is to be drawn on top of an existing plot" ] }, { "cell_type": "code", "execution_count": 4, "id": "5293ddf5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:42.293220Z", "iopub.status.busy": "2026-05-19T20:37:42.293097Z", "iopub.status.idle": "2026-05-19T20:37:42.504278Z", "shell.execute_reply": "2026-05-19T20:37:42.503919Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gr->Draw(\"ALP\");\n", "\n", "c1->Update();" ] }, { "cell_type": "markdown", "id": "d52898cb", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "bd2aa962", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:42.516365Z", "iopub.status.busy": "2026-05-19T20:37:42.516212Z", "iopub.status.idle": "2026-05-19T20:37:42.737152Z", "shell.execute_reply": "2026-05-19T20:37:42.736796Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%jsroot on\n", "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 }