# Plotting data points

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.

``````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.Draw("AP")
``````

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

it has this error:

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

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

My example from above converted to C++

``````#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->Draw("AP");
}
``````
``````#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.Draw("AP");
}
``````
``````#include <TGraph.h>
#include <TMultiGraph.h>
//...
auto mg = new TMultiGraph();
mg->Draw("AP");
//...
``````

FYI:

thanks very much

your fyi is noted… i’m sorry…

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?

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

Maybe log-axis?

``````gPad->SetLogy()
``````

Or scale one of the sets of y-values:

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

thanks… i tried the “scale”

yes, tried it… but thanks

``````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);