# Plotting points on the graph

**URL:** <https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791>\
**Category:** Newbie\
**Created:** [August 27, 2019, 3:32pm UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791 "2019-08-27T15:32:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 27, 2019, 3:32pm UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/1 "2019-08-27T15:32:48Z")

</div>

hi 🙂 i intend to plot points in TGraph with some part of the code:

```auto
 TF1 *f1 = new TF1("f1","(((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)), 0.0025, 1.0);
 f1->SetParameter(0,1.0);
 f1->SetParameter(1,1.0);
 f1->SetParameter(2,1.0/137.0);
 f1->SetParameter(3,gRandom->Gaus(0.938272081,0.000000023));
 f1->SetParameter(4,10.0);
 f1->SetParameter(5,TMath::Pi());
 f1->SetParameter(7,2.793);
 f1->SetLineColor(kBlue);
 f1->SetLineWidth(2);

 //auto av3 = new TGraph(nop);
 TGraph *av3 = new TGraph();
 TGraph *av3 = new TGraph();
 Double_t xpt, ypt;

 av3->GetPoint(1, xpt, ypt);
 av3->SetPoint(1, 0.40, f1->Eval(0.40));

```

but i got an error…

```auto
In file included from input_line_12:1:
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:98:25: warning: missing terminating '"' character [-Winvalid-pp-token]
 TF1 *f1 = new TF1("f1","(((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*si...
                        ^
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:98:25: error: expected expression
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:113:2: error: use of undeclared identifier 'av3'
 av3->GetPoint(1, xpt, ypt);
 ^
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:114:2: error: use of undeclared identifier 'av3'
 av3->SetPoint(1, 0.40, f1->Eval(0.40));
 ^
/home/jaybee/CodesScattering/StatNewEPScatteringSample.C:151:11: error: use of undeclared identifier 'av3'
 mgp->Add(av3,"PL");

```

how will i make this work? please help 🙂

regards,  
jaybee

---

<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 27, 2019, 4:20pm UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/2 "2019-08-27T16:20:10Z")

</div>

Start with fixing:

> (…) missing terminating ‘"’ character (…)

BTW. Graph points are numbered from 0.

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 3:54am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/3 "2019-08-28T03:54:17Z")

</div>

gracias 🙂

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 4:46am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/4 "2019-08-28T04:46:57Z")

</div>

with reference to a part of a code below:

```auto
 Int_t nop=100;
 Double_t xpt, ypt, del = 0.9975/nop;
 Int_t k;

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  //xpt = del*j;
  av1->SetPoint(j, xpt, 0.0);
 }

 for (Int_t i=0; i<nof; i++)
 {
  for (Int_t j=0; j < nop; j++)
  {
   av1->GetPoint(j, xpt, ypt);
   av1->SetPoint(j, xpt, ypt + fpf[i]->Eval(xpt)/(Double_t)nof);
  }
 }

```

for this, i just wanted to plot xpt=0.40, 0.50, 0.6, and 0.75  
how is it done? please help 🙂

regards.  
jaybee

---

<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:** [August 28, 2019, 6:35am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/5 "2019-08-28T06:35:10Z")

</div>

> [@jbmagallanes](#):
>
> i just wanted to plot xpt=0.40, 0.50, 0.6, and 0.75  
> how is it done?

Make a graph with only these points.

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 9:47am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/6 "2019-08-28T09:47:02Z")

</div>

gracias, okay will try it…

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 9:59am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/7 "2019-08-28T09:59:07Z")

</div>

i don’t get it if i do this

```auto
 TGraph *av4 = new TGraph();

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  av4->SetPoint(j, xpt, 0.0);
 }

 for (Int_t i=0; i<nof; i++)
 {
   av4->GetPoint(k, xpt, ypt);
   av4->SetPoint(0, 0.40, ypt + ppf[i]->Eval(0.40)/(Double_t)nof);
   av4->SetPoint(1, 0.50, ypt + ppf[i]->Eval(0.50)/(Double_t)nof);
   av4->SetPoint(2, 0.60, ypt + ppf[i]->Eval(0.60)/(Double_t)nof);
   av4->SetPoint(3, 0.70, ypt + ppf[i]->Eval(0.70)/(Double_t)nof);
   av4->SetPoint(4, 0.80, ypt + ppf[i]->Eval(0.80)/(Double_t)nof);
   av4->SetPoint(5, 0.98, ypt + ppf[i]->Eval(0.98)/(Double_t)nof);
 }

```

---

<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:** [August 28, 2019, 10:23am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/8 "2019-08-28T10:23:42Z")

</div>

You set the points in the same graph av4 … I suggested to take the points you need in av4 and put them in a new one av5

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 10:41am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/9 "2019-08-28T10:41:43Z")

</div>

i see… i’ll take your suggestion… 🙂 but i have a problem with ppf[i] because “i” runs from 0 to nof-1.

---

<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:** [August 28, 2019, 10:55am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/10 "2019-08-28T10:55:34Z")

</div>

> [@jbmagallanes](#):
>
> i have a problem with ppf[i] because “i” runs from 0 to nof-1.

I do not see why this is a problem …

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 11:04am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/11 "2019-08-28T11:04:23Z")

</div>

because i do not know which “i”… can you suggest to me the code?

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 11:06am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/12 "2019-08-28T11:06:24Z")

</div>

i did this

```auto
 TGraph *av4 = new TGraph();

 av4->GetPoint(k, xpt, ypt);
 av4->SetPoint(0, 0.40, ypt + ppf[nof]->Eval(0.40)/(Double_t)nof);
 av4->SetPoint(1, 0.50, ypt + ppf[nof]->Eval(0.50)/(Double_t)nof);
 av4->SetPoint(2, 0.60, ypt + ppf[nof]->Eval(0.60)/(Double_t)nof);
 av4->SetPoint(3, 0.70, ypt + ppf[nof]->Eval(0.70)/(Double_t)nof);
 av4->SetPoint(4, 0.80, ypt + ppf[nof]->Eval(0.80)/(Double_t)nof);
 av4->SetPoint(5, 0.98, ypt + ppf[nof]->Eval(0.98)/(Double_t)nof);

```

but it did not give the correct plot

---

<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:** [August 28, 2019, 11:12am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/13 "2019-08-28T11:12:14Z")

</div>

Something like that …

```auto
TGraph *av5 = new TGraph();
int j = 0;
for (Int_t i=0; i<nof; i++)
 {
   av4->GetPoint(i, xpt, ypt);
   if (xpt == 0.4 || xpt == 0.5 || xpt == 0.6 || apt = 0.75 ) { 
      av5->SetPoint(j, xpt, ypt + ppf[i]->Eval(xpt)/(Double_t)nof);
      j++;
   }
 }

```

But I am not complexity sure as you never sent a running example.

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 11:15am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/14 "2019-08-28T11:15:47Z")

</div>

okay… gracias… i will do this later after dinner 🙂

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 28, 2019, 4:16pm UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/15 "2019-08-28T16:16:06Z")

</div>

I could not see the specific points.  
Anyway, here is the complete code:

```auto
void StatNewEPScatteringSample01()
{
 static Int_t nof = 500; // number of functions to be generated
 auto can = new TCanvas("c1", "c1", 800,800); // setting the canvas
 //gStyle->SetOptStat("nerf");
 //gStyle->SetOptStat();
 gStyle->SetOptStat(0);
 can->Draw();

 auto avf = new TH1F("avf", "Average of Functions", 100, 0.0025, 1.0);
 avf->Draw();

//=== generating the functions ===//

 TF1 *fpf[nof], *ppf[nof];
 TString fna;

 for (Int_t i=0; i<nof; i++)
 {
  fna = "f"; fna += i;
  fpf[i] = new TF1("fna","(((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+2.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+(x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)))))*((2.0*[3]*[3])/(2.0*[3]*[3]+x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))))*((4.0*[3]*[3])/(4.0*[3]*[3]+x))*((0.71)/(0.71+x))*((0.71)/(0.71+x))*((0.71)/(0.71+x))*((0.71)/(0.71+x))*((8.0*[3]*[3]*[3]*[3]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+2.0*[3]*[3]*x*[6]*[6]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+4.0*[3]*[3]*x*[6]*[6]*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+x*x*[6]*[6]*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))/(8.0*[3]*[3]*[3]*[3])))", 0.0025, 1.0);
  fpf[i]->SetParameter(0,1.0);
  fpf[i]->SetParameter(1,1.0);
  fpf[i]->SetParameter(2,1.0/137.0);
  fpf[i]->SetParameter(3,gRandom->Gaus(0.938272081,0.000000023));
  fpf[i]->SetParameter(4,10.0);
  fpf[i]->SetParameter(5,TMath::Pi());
  fpf[i]->SetParameter(6,2.793);
 }

 for (Int_t i=0; i<nof; i++)
 {
  fna = "f"; fna += i;
  ppf[i] = new TF1("fna","((2.0*[0]*[0]*[1]*[1]*[2]*[2]*[3]*[3])/(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+2.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+(x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)))))*((2.0*[3]*[3])/(2.0*[3]*[3]+x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+sqrt(x*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))))*((2.0*[3]*[3]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0))/(2.0*[3]*[3]))", 0.0025, 1.0);
  ppf[i]->SetParameter(0,1.0);
  ppf[i]->SetParameter(1,1.0);
  ppf[i]->SetParameter(2,1.0/137.0);
  ppf[i]->SetParameter(3,gRandom->Gaus(0.938272081,0.000000023));
  ppf[i]->SetParameter(4,10.0);
  ppf[i]->SetParameter(5,TMath::Pi());
  ppf[i]->SetParameter(6,2.793);
 }

//=== getting the average ===//

 Int_t nop=100;
 Double_t xpt, ypt, del = 0.9975/nop;

 TGraph *av1 = new TGraph();

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  av1->SetPoint(j, xpt, 0.0);
 }
 for (Int_t i=0; i<nof; i++)
 {
  for (Int_t j=0; j < nop; j++)
  {
   av1->GetPoint(j, xpt, ypt);
   av1->SetPoint(j, xpt, ypt + fpf[i]->Eval(xpt)/(Double_t)nof);
  }
 }

 TGraph *av2 = new TGraph();

 for (Int_t j=0; j < nop; j++)
 {
  xpt = del*j + 0.0025*del;
  av2->SetPoint(j, xpt, 0.0);
 }

 for (Int_t i=0; i<nof; i++)
 {
  for (Int_t j=0; j < nop; j++)
  {
   av2->GetPoint(j, xpt, ypt);
   av2->SetPoint(j, xpt, ypt + ppf[i]->Eval(xpt)/(Double_t)nof);
  }
 }

 TGraph *av4 = new TGraph();
 int j = 0;

 for (Int_t i=0; i<nof; i++)
 {
   av2->GetPoint(i, xpt, ypt);
   if (xpt == 0.4 || xpt == 0.5 || xpt == 0.6 || xpt == 0.75 ) {
                                                                av4->GetPoint(i, xpt, ypt);
                                                                av4->SetPoint(j, xpt, ypt + ppf[i]->Eval(xpt)/(Double_t)nof);
                                                                j++;
                                                               }
 }

//=== pLotting the average on canvas ===//

 gPad->SetLogy(1);

 av1->SetMarkerStyle(7);
 av1->SetMarkerColor(kBlue);
 av1->SetMarkerSize(1);

 av2->SetMarkerStyle(6);
 av2->SetMarkerColor(kRed);
 av2->SetMarkerSize(1);

 av4->SetMarkerStyle(3);
 av4->SetMarkerColor(kMagenta);
 av4->SetMarkerSize(1);

 TMultiGraph *mgp = new TMultiGraph();
 mgp->SetMinimum(1.e-4);
 mgp->SetMaximum(1.e0);
 mgp->Add(av1,"PL");
 mgp->Add(av2,"PL");
 mgp->Add(av4,"PL");
 mgp->Draw("a");

 avf->SetMaximum(1.e0);
 can->Modified();
 can->Update();
}

```

please help me about this.

---

<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:** [August 29, 2019, 6:50am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/16 "2019-08-29T06:50:13Z")

</div>

your code gives me:

```auto
root [0] 
Processing StatNewEPScatteringSample01.C...
Error in <TGraphPainter::PaintGraph>: illegal number of points (0)

```

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 29, 2019, 7:03am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/17 "2019-08-29T07:03:36Z")

</div>

what does it mean? ☹

---

<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:** [August 29, 2019, 7:14am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/18 "2019-08-29T07:14:19Z")

</div>

It means that one of your graph has 0 points

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [August 29, 2019, 7:15am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/19 "2019-08-29T07:15:44Z")

</div>

that would be av4… but i do not know the reason why?

---

<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:** [August 29, 2019, 7:19am UTC](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791/20 "2019-08-29T07:19:18Z")

</div>

because the test:

```auto
if (xpt == 0.4 || xpt == 0.5 || xpt == 0.6 || xpt == 0.75 ) 

```

is never true

[Next page](https://root-forum.cern.ch/t/plotting-points-on-the-graph/35791.md?page=2)
