# Drawing TGraphErr

**URL:** <https://root-forum.cern.ch/t/drawing-tgrapherr/51357>\
**Category:** Newbie\
**Created:** [August 26, 2022, 2:42pm UTC](https://root-forum.cern.ch/t/drawing-tgrapherr/51357 "2022-08-26T14:42:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dil/32/26887_2.png) [@Dil](https://root-forum.cern.ch/u/Dil)\
**Post date:** [August 26, 2022, 2:42pm UTC](https://root-forum.cern.ch/t/drawing-tgrapherr/51357/1 "2022-08-26T14:42:05Z")

</div>

Hello Rooters,

I am trying to draw a TGraphErr for my separate binning(Attached2D histogram).But I got empty canvas.Could you please help me?

Please see the snippet.

```auto
const int nxB=3, nQ2=4;

int nbins_mpipi=5.0;
int nbins_tmin_t=10;
          
TCanvas *canxBQ2_t_tmin_vs_mpipi_graphs= new TCanvas("canxBQ2_t_tmin_vs_mpipi_graphs","",12000,6000);
    canxBQ2_t_tmin_vs_mpipi_graphs->Divide(nxB,nQ2);

int z=0;
 // Loop over Q2, xB bins
for (int iQ2=0; iQ2<nQ2; iQ2++) {
        for (int ixB=0; ixB<nxB; ixB++) {
            z++;
            canxBQ2_t_tmin_vs_mpipi_graphs->cd(z);
            //Drawing Tgraph
            double XX[nbins_mpipi], YY[nbins_tmin_t], ERR[nbins_mpipi];
            TGraphErrors *gEff = new TGraphErrors(nbins_mpipi, XX,YY,ERR);
         
                 for (int jtmin_t=0; jtmin_t<nbins_tmin_t; jtmin_t++)
                 {
                      for (int ipipi=0; ipipi<nbins_mpipi; ipipi++)
                      {
                           XX[ipipi] = h_t_tmin_vs_mpipi_ratio[iQ2][ixB]->GetBinContent(ipipi+1);
                           YY[jtmin_t] = h_t_tmin_vs_mpipi_ratio[iQ2][ixB]->GetBinContent(jtmin_t+1);
                           ERR[ipipi]= h_t_tmin_vs_mpipi_ratio[iQ2][ixB]->GetBinError(ipipi+1);
                       }
                       gEff->SetMarkerColor(jtmin_t+1);
                       gEff->Draw("ALP");
                 }
           
}

}

```

[4.pdf](https://root-forum.cern.ch/uploads/short-url/gTZJuUdvB4XG5OTJ7qURHiFjrIt.pdf) (40.1 KB)

---

<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:** [August 26, 2022, 2:49pm UTC](https://root-forum.cern.ch/t/drawing-tgrapherr/51357/2 "2022-08-26T14:49:59Z")

</div>

Move the line:  
`TGraphErrors *gEff = new TGraphErrors(nbins_mpipi, XX,YY,ERR);`  
to a place right before the line:  
`gEff->SetMarkerColor(jtmin_t+1);`

---

<div class="post-metadata">

**Author:** ![Dil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dil/32/26887_2.png) [@Dil](https://root-forum.cern.ch/u/Dil)\
**Post date:** [August 26, 2022, 2:55pm UTC](https://root-forum.cern.ch/t/drawing-tgrapherr/51357/3 "2022-08-26T14:55:28Z")

</div>

Thank You, [Wile\_E\_Coyote](https://root-forum.cern.ch/t/drawing-tgrapherr/51357/2)  
This is a stupid mistake.

But still I haven’t got what I want.  
Just wondering is this following part is okay???

```auto
XX[ipipi] = h_t_tmin_vs_mpipi_ratio[iQ2][ixB]->GetBinContent(ipipi+1);
 YY[jtmin_t] = h_t_tmin_vs_mpipi_ratio[iQ2][ixB]->GetBinContent(jtmin_t+1);

```

[10.pdf](https://root-forum.cern.ch/uploads/short-url/yUsvFcjbxTHBUi9fplwGsemRl5s.pdf) (18.9 KB)

---

<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:** [August 26, 2022, 3:05pm UTC](https://root-forum.cern.ch/t/drawing-tgrapherr/51357/4 "2022-08-26T15:05:56Z")

</div>

I guess you need: `YY[ipipi] = ...`
