# How to add text in graph

**URL:** <https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335>\
**Category:** Newbie\
**Tags:** root\
**Created:** [May 9, 2020, 1:41pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335 "2020-05-09T13:41:35Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [May 9, 2020, 1:41pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/1 "2020-05-09T13:41:35Z")

</div>

Hi !  
I am working on a code to add text to my graph but it is not able to write more than one line in the graph or canvas.  
[efficiency\_R.C](https://root-forum.cern.ch/uploads/short-url/s4aLv5SObECQVcw4DWY0zYRulDR.C) (1.9 KB) [rad\_9.txt](https://root-forum.cern.ch/uploads/short-url/saFVQaEPXltuGiulLlquIOyGWoK.txt) (340 Bytes)

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 9, 2020, 1:46pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/2 "2020-05-09T13:46:10Z")

</div>

[TPaveText](https://root.cern/doc/master/classTPaveText.html)

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [May 9, 2020, 2:01pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/3 "2020-05-09T14:01:10Z")

</div>

@Wile_E_Coyote  
Actually I used TpaveText in my code.  
Still I am not able to write more than one line in canvas.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 10, 2020, 5:28am UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/4 "2020-05-10T05:28:11Z")

</div>

Read the reference page; you need to provide the coordinates of the box when you create a TPaveText.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 11, 2020, 7:01am UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/5 "2020-05-11T07:01:31Z")

</div>

```auto
#include "TFile.h"
#include "TGraphErrors.h"
#include "TF1.h"

Double_t Fit1(Double_t *x, Double_t *par)
{
        Double_t arg1 = TMath::Log(0.01*x[0]); // in keV
        Double_t arg2 = TMath::Log(0.001*x[0]); // in keV

            Double_t fit_val = TMath::Exp(TMath::Power((TMath::Power((par[0]+par[1]*arg1+par[2]*arg1*arg1),(-1.0*par[3]))+TMath::Power((par[4]+par[5]*arg2+par[6]*arg2*arg2),(-1.0*par[3]))),(-1.0*1/par[3])))/1000.;
        return fit_val;
}

void efficiency_R() {
   TGraphErrors *g = new TGraphErrors("rad_9.txt", "%lg %lg %lg");
   TF1 *RT = new TF1("RT",Fit1,100.,1500.,7.);

   //rad 6,7
   RT->SetParameter(0,16.);
   RT->SetParameter(1,7.5);
   RT->FixParameter(2,0.);
   RT->FixParameter(3,15.);
   RT->SetParameter(4,15.);
   RT->SetParameter(5,-0.78);
   RT->SetParameter(6,.015);

   RT->Draw("L");
   g->SetMaximum(15000.);//along Y
   g->Fit("RT","IER");
   g->SetMarkerStyle(3);
   g->Draw("AP");
   g->SetTitle("Efficiency Vs Energy(keV);Energy;Efficiency");
   gStyle->SetOptFit(111); //showing the parameters on graph

   TPaveText *pt = new TPaveText(77.6016,12857.83,971.9464,14578.31);
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetFillStyle(0);
   pt->AddText("Exp{[(P0+P1*X+P2*X*X)**(-P3)+(P4+P5*Y+P6*Y*Y)**(-P3)]**(-1/P3)}");
   pt->AddText("WITH X = LOG (X/100) & Y = LOG (X/1000)");
   pt->Draw();

   double par[7];
   RT->GetChisquare();
   RT->GetParameters(par);
   double a = 700.0, y;
   y = RT->Eval(a);
   cout << "y = "<<y<<endl;
}

```

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [May 11, 2020, 3:56pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/6 "2020-05-11T15:56:53Z")

</div>

@couet  
can I get directly the value of chi square written in the stat box? If yes, then what I have to use?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 12, 2020, 6:47am UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/7 "2020-05-12T06:47:06Z")

</div>

```auto
RT->GetChisquare();

```

---

<div class="post-metadata">

**Author:** ![robertfroast](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/robertfroast/32/21121_2.png) [@robertfroast](https://root-forum.cern.ch/u/robertfroast)\
**Post date:** [May 12, 2020, 1:23pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/8 "2020-05-12T13:23:56Z")

</div>

@couet  
I used this but I am talking about the stat box in the canvas.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 12, 2020, 1:39pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/9 "2020-05-12T13:39:41Z")

</div>

[`gStyle->SetOptFit(100);`](https://root.cern/doc/master/classTStyle.html#aedeb1d117d9f16af9f8ad430bf956d64)

@couet Maybe you could copy (“replicate”) the very first “Note” from [TStyle::SetOptStat](https://root.cern/doc/master/classTStyle.html#a0ae6f6044b6d7a32756d7e98bb210d6c) to [TStyle::SetOptFit](https://root.cern/doc/master/classTStyle.html#aedeb1d117d9f16af9f8ad430bf956d64).

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 12, 2020, 1:57pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/10 "2020-05-12T13:57:50Z")

</div>

@robertfroast sorry I understood the opposite. see Wile answer  
@Wile_E_Coyote yes it makes sense.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 12, 2020, 2:07pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/11 "2020-05-12T14:07:34Z")

</div>

PR ready: [https://github.com/root-project/root/pull/5602](https://github.com/root-project/root/pull/5602)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 12, 2020, 2:21pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/12 "2020-05-12T14:21:30Z")

</div>

@couet

```cpp
 /// - never call SetOptFit(0111) but call SetOptFit(111) or SetOptFit(10111), 0111 will

```

and then also maybe correct:

```cpp
 /// - never call SetOptStat(000000111) but call SetOptStat(111) or SetOptStat(1000000111), 000000111 will

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 12, 2020, 2:34pm UTC](https://root-forum.cern.ch/t/how-to-add-text-in-graph/39335/13 "2020-05-12T14:34:17Z")

</div>

Yes @bellenot saw it also (PR reviewer). Thanks !
