# Plotting data points

**URL:** <https://root-forum.cern.ch/t/plotting-data-points/27623>\
**Category:** ROOT\
**Created:** [January 18, 2018, 5:57pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623 "2018-01-18T17:57:54Z")\
**Posts on this page:** 15\
**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:** [January 18, 2018, 5:57pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/1 "2018-01-18T17:57:54Z")

</div>

how do you plot two sets of data points with the same x-range (same values) but with different y-range? For example: {(0,5); (1,7); (2,10); (3,15)} and {(0,1000); (1,2000); (2,10000); (3,1500000)}. Thanks for your help.

---

<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:** [January 18, 2018, 5:59pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/2 "2018-01-18T17:59:19Z")

</div>

[TMultiGraph](https://root.cern.ch/doc/master/classTMultiGraph.html)

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [January 18, 2018, 6:01pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/3 "2018-01-18T18:01:38Z")

</div>

```python
import numpy as np
import ROOT

x = np.array([0,1,2,3], dtype='float64')
y1 = np.array([5,7,10,15], dtype='float64')
y2 = np.array([1000,2000,10000,1500000], dtype='float64')

g1 = ROOT.TGraph(len(x), x, y1)
g2 = ROOT.TGraph(len(x), x, y2)

mg = ROOT.TMultiGraph()
mg.Add(g1)
mg.Add(g2)

mg.Draw("AP")

```

---

<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:** [January 18, 2018, 6:10pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/4 "2018-01-18T18:10:44Z")

</div>

thanks ksmith 🙂 i will try to figure it out… i am actually doing two for-loops that give out two different values for the same x 🙂

---

<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:** [January 18, 2018, 7:09pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/5 "2018-01-18T19:09:52Z")

</div>

it has this error:

error: no member named  
’TMultiGraph’ in namespace 'ROOT’  
mg = ROOT::TMultiGraph()

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [January 18, 2018, 7:13pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/6 "2018-01-18T19:13:44Z")

</div>

What language are you using? Can you post a small example?

My example from above converted to C++

```auto
#include<array>                                                          
                                                                         
#include <TGraph.h>                                                      
#include <TMultiGraph.h>                                                 
                                                                         
{                                                                        
   std::array<Int_t, 4> x = {0,1,2,3};                                   
   std::array<Int_t, 4> yData1 = {5,7,10,15};                              
   std::array<Int_t, 4> yData2 = {1000,2000,10000,1500000};                              
                                                                         
   auto g1 = new TGraph(4, x.data(), yData1.data());                     
   auto g2 = new TGraph(4, x.data(), yData2.data());                     
                                                                         
   auto mg = new TMultiGraph();                                          
   mg->Add(g1);                                                          
   mg->Add(g2);                                                          
                                                                         
   mg->Draw("AP");                                                       
}

```

---

<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:** [January 18, 2018, 7:38pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/7 "2018-01-18T19:38:22Z")

</div>

```auto
#include "TF1.h"
#include "Math/WrappedTF1.h"
#include "Math/GaussIntegrator.h"

void program002rootforum()
{
 int N = 20;
 double a = 0.5;
 double m = 1.0;
 double E = 0.5;
 double s = 1.0;
 double p = m / (2.0*a);
 double q = m / a;
 double xi = 0.0;
 double r = m / (2.0*a);
 double w = a / 2.0;
 double u = m / (2.0*a);
 double v = m / a;
 double xf = 2.0;
 double xd = (xf-xi) / N;

 g = new TGraph();
 g1 = new TGraph();

 for(i=0; i<N; i++)
 {
  double x, y;

  x = xd * i;
  y = exp(x*x/2.0);
  g -> SetPoint (i, x, y);
  g -> SetMarkerStyle(28);
 }

 for(i=0; i<N; i++)
 {
  double x, y;

  x = xd * i;
  y = exp(-x*x/2.0) / (sqrt(sqrt(TMath::Pi())))*exp(-E*a*N);
  g1 -> SetPoint (i, x, y);
  g1 -> SetMarkerStyle(28);
 }

 mg = ROOT::TMultiGraph();
 mg.Add(g);
 mg.Add(g1);
 mg.Draw("AP");
}

```

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [January 18, 2018, 7:39pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/8 "2018-01-18T19:39:34Z")

</div>

```auto
#include <TGraph.h>
#include <TMultiGraph.h>
//...
auto mg = new TMultiGraph();
mg->Add(g);
mg->Add(g1);
mg->Draw("AP");
//...

```

FYI:

> [@Getting the same histograms after cuts](https://root-forum.cern.ch/t/getting-the-same-histograms-after-cuts/24719/2):
>
> Remark on the way to post code snippets: When you post pieces of code on the forum enclose it with ``` . That makes your post much more readable (I systematically edit your posts that way) . So do: ``` // this is a C++ piece of code. ``` And it will display as: // this is a C++ piece of 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:** [January 18, 2018, 7:50pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/9 "2018-01-18T19:50:03Z")

</div>

thanks very much 🙂

your fyi is noted… i’m sorry…

---

<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:** [January 18, 2018, 8:07pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/10 "2018-01-18T20:07:03Z")

</div>

It worked!!!

But there is another catch.  
The y-values of “g1” are nearly visible because they are very small.  
It makes only a horizontal line at the bottom.  
The other graph is visible because its y-values are really large.  
How do I scale the y-values of “g1” to make both graphs visible? 🙂

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [January 18, 2018, 8:11pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/11 "2018-01-18T20:11:40Z")

</div>

> [@jbmagallanes](#):
>
> your fyi is noted… i’m sorry…

No worries, you’ll get better response with eay to read posts.

> [@jbmagallanes](#):
>
> The y-values of “g1” are nearly visible because they are very small.  
> It makes only a horizontal line at the bottom.  
> The other graph is visible because its y-values are really large.  
> How do I scale the y-values of “g1” to make both graphs visible?

Maybe log-axis?

```auto
gPad->SetLogy()

```

Or scale one of the sets of y-values:

```auto
scale = 1000;
y = exp(x*x/2.0) * scale;

```

---

<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:** [January 18, 2018, 8:26pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/12 "2018-01-18T20:26:23Z")

</div>

thanks… i tried the “scale” 🙂

---

<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:** [January 18, 2018, 11:01pm UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/13 "2018-01-18T23:01:31Z")

</div>

yes, tried it… but thanks 🙂

---

<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:** [January 22, 2018, 10:13am UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/14 "2018-01-22T10:13:45Z")

</div>

```auto
void program002rootforum()
{
   int N = 20;
   double a = 0.5;
   double m = 1.0;
   double E = 0.5;
   double s = 1.0;
   double p = m / (2.0*a);
   double q = m / a;
   double xi = 0.0;
   double r = m / (2.0*a);
   double w = a / 2.0;
   double u = m / (2.0*a);
   double v = m / a;
   double xf = 2.0;
   double xd = (xf-xi) / N;

   TGraph *g = new TGraph();
   TGraph *g1 = new TGraph();

   double x, y;
   int i;

   g->SetMarkerStyle(28);
   for (i=0; i<N; i++) {
      x = xd * i;
      y = exp(x*x/2.0);
      g->SetPoint (i, x, y);
   }

   g1 -> SetMarkerStyle(27);
   for (i=0; i<N; i++) {
      x = xd * i;
      y = exp(-x*x/2.0) / (sqrt(sqrt(TMath::Pi())))*exp(-E*a*N);
      g1 -> SetPoint (i, x, y);
   }

   TMultiGraph *mg = new TMultiGraph();
   mg->SetMinimum(0.0005);
   mg->Add(g);
   mg->Add(g1);
   mg->Draw("AP");
   gPad->SetLogy(1);
}

```

 ![07](https://root-forum.cern.ch/uploads/default/original/2X/e/e537e57f4644dcf2213a8a84606a88e006f890e2.jpg)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 5, 2018, 10:13am UTC](https://root-forum.cern.ch/t/plotting-data-points/27623/15 "2018-02-05T10:13:54Z")

</div>

Closed on February 5, 2018, 10:13am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
