# How to plot TGraphErrors from a tree

**URL:** <https://root-forum.cern.ch/t/how-to-plot-tgrapherrors-from-a-tree/9233>\
**Category:** ROOT\
**Created:** [November 13, 2009, 8:09pm UTC](https://root-forum.cern.ch/t/how-to-plot-tgrapherrors-from-a-tree/9233 "2009-11-13T20:09:42Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![theovaf](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/c4cdca/32.png) [@theovaf](https://root-forum.cern.ch/u/theovaf)\
**Post date:** [November 15, 2009, 6:02pm UTC](https://root-forum.cern.ch/t/how-to-plot-tgrapherrors-from-a-tree/9233/5 "2009-11-15T18:02:48Z")

</div>

yes i have noticed and implemented your change but had the same results.  
so my exact code is the following:

```cpp
// creating the tree:

sprintf(treename,"Radon Data",200000);
    sprintf(treetitle,"Tree of the Radon Data");

    TTree *tree = (TTree*)outRf->Get(treename);

    if (tree==NULL)
    {
	tree = new TTree(treename,treetitle);

	tree->Branch("labviewtime", &labviewtime, "labviewtime/D");
	tree->Branch("HumidityRel.", &data[0], "HumidityRel./D");
	tree->Branch("AirPressure", &data[1], "AirPressure/D");
	tree->Branch("Rn222", &data[2], "Rn222/D");
	tree->Branch("Rn222error", &data[3], "Rn222error/D");
	tree->Branch("Temperature", &data[4], "Temperature/D");
    }
    
}
// i fill the Ttree named tree..
}

const int N=nlines-1;
    double x[N],y[N],yerr[N];
    
      for (int k=0;k<N;k++)
      {x[N]=0;y[N]=0;yerr[N]=0;
      }
      
    TBranch *Tlabviewtime=tree->GetBranch("labviewtime");
    TBranch *TRn222=tree->GetBranch("Rn222");
    TBranch *TRn222error=tree->GetBranch("Rn222error");
    Tlabviewtime->SetAddress(x);
    TRn222->SetAddress(y);
    TRn222error->SetAddress(yerr);
    
   for (int k=0;k<N-1;k++)
    {
      x[k]=Tlabviewtime->GetEntry(k);
      cout<<x[k]<<endl;
      y[k]=TRn222->GetEntry(k);
      yerr[k]=TRn222error->GetEntry(k);
    }
    
   
   TCanvas *c1 = new TCanvas("c1","Radon",200,10,700,500);

   c1->SetFillColor(42);
   c1->SetGrid();
   c1->GetFrame()->SetFillColor(21);
   c1->GetFrame()->SetBorderSize(12);

   //const Int_t n = 10;
   
   TGraphErrors *gr = new TGraphErrors(N,x,y,0,yerr);
   
   gr->SetTitle("Radon");
   //gr->SetMarkerColor(4);
   //gr->SetMarkerStyle(21);
   //gr->SetLineColor(4);
   gr->Draw("LPA");
   c1->Update();

```

hope this helps  
cheers

---

_[View the full topic](https://root-forum.cern.ch/t/how-to-plot-tgrapherrors-from-a-tree/9233)._
