# TMultiGraph

Dear ROOT experts,

I’m trying to plot in two differents pads :

1. one first graph
2. the same with a second
using TMultiGraph, in the following script :

#include <stdio.h>
#include <math.h>
#define N 100
Int_t main(void)
{
Int_t i;
Double_t x[N],y[N],pi=acos(-1.);
TCanvas *c1=new TCanvas(“c1”,“c1”,10,10,1200,900);
c1->Divide(2);
TMultiGraph *mgh=new TMultiGraph();
//… Plot of graph #1
for(i=0; i<N; i++){x[i]=(Double_t)i/(N-1)*2.*pi; y[i]=sin(x[i]);}
TGraph *gr=new TGraph(N,x,y);
c1->cd(1); mgh->Draw(“AL”);
c1->Update();
//… Plot of graph #1 and graph #2
for(i=0; i<N; i++){x[i]=(Double_t)i/(N-1)*2.*pi; y[i]=cos(x[i]);}
TGraph *gr=new TGraph(N,x,y);
c1->cd(2); mgh->Draw(“AL”);
}

The pad cd(1), and not only cd(2), contain the two graphs. Why ? (ROOT 3.05/05)

``                                                     Thank You``

Dear Naulin,

I am not as much an expert (actually, I am here to get an easy question answered myself ) but as far as I understand ROOT does a modification of a object already created and drawn on the screen imply, that the existing picture of the object itself is modified - upon the next Update().

So when you are adding a second graph to the existing multigraph and draw the same multigraph again, it will show identical graphs in both pads.

Your intension, however, was to show only the first plot in the first pad (different pictures). To do so, I would copy the multipad with the Clone() method before adding the second Graph.

#include <stdio.h>
#include <math.h>
#define N 100
Int_t multigraph(void)
{
Int_t i;
Double_t x[N],y[N],pi=acos(-1.);
TCanvas *c1=new TCanvas(“c1”,“c1”,10,10,1200,900);
c1->Divide(2);
TMultiGraph *mgh=new TMultiGraph();
//… Plot of graph #1
for(i=0; i<N; i++){
x[i]=(Double_t)i/(N-1)*2.*pi;
y[i]=sin(x[i]);
}
TGraph *gr=new TGraph(N,x,y);
c1->cd(1); mgh->Draw(“APL”);
c1->Update();
[color=darkred] TMultiGraph *mgh2= (TMultiGraph *) mgh->Clone(); [/color]
//… Plot of graph #1 and graph #2
for(i=0; i<N; i++){
x[i]=(Double_t)i/(N-1)*2.*pi;
y[i]=cos(x[i]);
}
TGraph *gr=new TGraph(N,x,y);