# Plotting only one point on canvass

**URL:** <https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719>\
**Category:** Newbie\
**Created:** [November 6, 2019, 9:26pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719 "2019-11-06T21:26:53Z")\
**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:** [November 6, 2019, 9:26pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/1 "2019-11-06T21:26:53Z")

</div>

hi everyone 🙂 i would have wanted to print only just one point on a canvass.  
kindly, see part of the code.

```auto
//=== generating the functions ===//
 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))*([7]*[7]*[8]*[8]*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+[6]*[6]*[7]*[7]*(2.0*[3]*[3]*x*cos([4]*[5]/360.0)*cos([4]*[5]/360.0)+4.0*[3]*[3]*x*sin([4]*[5]/360.0)*sin([4]*[5]/360.0)+x*x*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.000000006));
  fpf[i]->SetParameter(4,27.0);
  fpf[i]->SetParameter(5,TMath::Pi());
  fpf[i]->SetParameter(6,2.792847351);
  fpf[i]->SetParameter(7,gRandom->Gaus(0.979,0.022)+gRandom->Gaus(0.0,0.010));
  fpf[i]->SetParameter(8,gRandom->Gaus(0.914,0.024)+gRandom->Gaus(0.0,0.010));
 }

 Int_t nop=300;

 Double_t xpt, ypt, del = 0.9975/nop;

 auto av1 = new TGraph(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);
  }
 }

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

//=== Plotting the point on canvas ===//
int j = 0;

TGraph *av0000 = new TGraph();
double q20 = 0.399008;
double eps = 0.01;

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

 av0000->SetMarkerStyle(22);
 av0000->SetMarkerColor(3); //green
 av0000->SetMarkerSize(1);

TMultiGraph *mgp = new TMultiGraph();
 mgp->SetTitle("dcs of ep, eq_s, eq_c (with mrf); Transfer Momentum in GeV^2; Differential Cross Section");
 mgp->SetMinimum(1.e-5);
 mgp->SetMaximum(1.e0);
 mgp->Add(av0000,"*");

```

but I get a curve of points.

 ![Screenshot%20from%202019-11-06%2021-26-11](https://root-forum.cern.ch/uploads/default/original/3X/7/d/7dc57b31da5fae58c5739785503f5e1709a3ce59.png)

---

<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:** [November 7, 2019, 8:05am UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/2 "2019-11-07T08:05:19Z")

</div>

In the code you posted we do not see the drawing part.

---

<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:** [November 7, 2019, 4:01pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/3 "2019-11-07T16:01:44Z")

</div>

is this what you mean?:

```auto
TMultiGraph *mgp = new TMultiGraph();
 mgp->SetTitle("dcs of ep, eq_s, eq_c (with mrf); Transfer Momentum in GeV^2; Differential Cross Section");
 mgp->SetMinimum(1.e-5);
 mgp->SetMaximum(1.e0);
 mgp->Add(av0000,"*");

```

---

<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:** [November 7, 2019, 4:14pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/4 "2019-11-07T16:14:40Z")

</div>

Well … It would be better to see the whole macro… But: if you put in a multigraph several graphs having several points how can you see only one point ?

---

<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:** [November 7, 2019, 4:34pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/5 "2019-11-07T16:34:33Z")

</div>

i will send the macro in the email… each graph should only contain one point in this case 🙂

---

<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:** [November 8, 2019, 7:47am UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/6 "2019-11-08T07:47:15Z")

</div>

Please send working code. I get:

```auto
Processing TheMacro.C...
In file included from input_line_9:1:
/Users/couet/Downloads/TheMacro.C:1458:17: error: invalid suffix '.498758' on floating constant
double q21 = 0.0.498758;

```

Also, no need to send the code by private email. post it here as attachement.

---

<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:** [November 8, 2019, 3:57pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/7 "2019-11-08T15:57:25Z")

</div>

gracias… okay, I will  
[DataPoints.C](https://root-forum.cern.ch/uploads/short-url/qm1kQOeoh5KQBEvVjobqEtBuICq.C) (95.1 KB)

---

<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:** [November 8, 2019, 4:05pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/8 "2019-11-08T16:05:57Z")

</div>

Your macro gives me this plot. What is wrong with it ?

 ![13](https://root-forum.cern.ch/uploads/default/original/3X/9/6/96cd5d21b3c93f14d8d538ab05c3b5efa0bbcd25.jpeg)

---

<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:** [November 8, 2019, 4:12pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/9 "2019-11-08T16:12:41Z")

</div>

I think you always need:

```cpp
TGraph *av... = new TGraph();
j = 0; // "reset" it

```

---

<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:** [November 8, 2019, 4:12pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/10 "2019-11-08T16:12:50Z")

</div>

Basically your macro does:

```auto
 mgp->Add(av0000,"PL");
 mgp->Draw("a");

```

av0000 has 3 points…we see 3 points … all is fine .

---

<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:** [November 8, 2019, 4:26pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/11 "2019-11-08T16:26:08Z")

</div>

i see… i will tweak it again… 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:** [November 8, 2019, 4:38pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/12 "2019-11-08T16:38:32Z")

</div>

could it be the version of ROOT?  
5-34-32  
5-34-34  
5-34-36

---

<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:** [November 8, 2019, 6:02pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/13 "2019-11-08T18:02:17Z")

</div>

unrelated question:  
How do I store the output text in to a file?  
I mean, the command to do it?

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:** [November 8, 2019, 6:30pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/14 "2019-11-08T18:30:59Z")

</div>

[cplusplus.com -\> Tutorials -\> C++ Language -\> Input/output with files](http://www.cplusplus.com/doc/tutorial/files/)

---

<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:** [November 8, 2019, 6:36pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/15 "2019-11-08T18:36:57Z")

</div>

If you want to use ROOT 5, you need to get rid of all c++11 and newer statements in your macro (e.g. “auto”).

---

<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:** [November 8, 2019, 10:50pm UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/16 "2019-11-08T22:50:52Z")

</div>

I could not anymore recognize which are C++ statements in the code but I have commented all the “auto” code[DataPointStatNewEPEQDCSProbColorWithMRF02.C](https://root-forum.cern.ch/uploads/short-url/r0oqytdBBZ7uRE5ldazUo3Ttgcu.C) (95.2 KB) . But the output is still the same 🙂

---

<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:** [November 9, 2019, 7:20am UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/17 "2019-11-09T07:20:23Z")

</div>

I get the same plot as @couet with ROOT 5.34/36.

You can add:

```auto
#include "TCanvas.h"
#include "TPad.h"
#include "TStyle.h"
#include "TH1.h"
#include "TF1.h"
#include "TString.h"
#include "TRandom3.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TMath.h"

```

and then try:  
`root [0] .x DataPointStatNewEPEQDCSProbColorWithMRF02.C++`

Note: an unused variable “av0002”: `TGraph *av0002 = new TGraph();`

BTW. in order to simplify your code (you can get rid of “j”), you can use:  
`av...->SetPoint(av...->GetN(), xpt, ypt + ...); // append a new point`

---

<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:** [November 10, 2019, 2:54am UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/18 "2019-11-10T02:54:21Z")

</div>

okay… muchas gracias… i will implement your suggestions 🙂

---

<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:** [November 10, 2019, 3:03am UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/19 "2019-11-10T03:03:40Z")

</div>

yeah… it worked… 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:** [November 10, 2019, 4:47am UTC](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719/20 "2019-11-10T04:47:42Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> av…-\>SetPoint(av…-\>GetN(), xpt, ypt + …); // append a new point

do i need to put the data point number in …-GetN(241) [for example]…

[Next page](https://root-forum.cern.ch/t/plotting-only-one-point-on-canvass/36719.md?page=2)
