TMultiGraph draw options

Hi all,

Some of the TMultiGraph draw options don’t as they do for TGraph.
For example, .Draw(“AY+X+”); doesn’t work.

Additionally, applying this example: root.cern.ch/phpBB2/viewtopic.ph … ose+tgraph
to MultiGraphs doesn’t work correctly, making it essentially impossible to draw two superimposed multigraphs.
The problem is that the X axis of the two multigraphs don’t overlap (like they do with graphs), creating 2 systems of X axis.

Please look at attached example

  • Toggle drawMultiGraphs to switch between drawing multigraphs and normal graphs
  • Change rangeFunc to switch between the 3 functions of setting graph ranges.


    example2.C (3.21 KB)

I will look at your file. But I am wondering why you need to use several multigraphs on top of each other ? A multigraph is meant to be used as a container of graphs in order to compute a common scale to all of them. In the picture you show using simple graphs is enough. I am wondering you need to use multigraphs instead ?

A simple description of my problem:
Two sources of data that I want to compare, both producing different readings in Y axis (widely different ranges for each) and different readings for X axis (representing sample time of each of the 2 sensors).

Since the data from both sensors affect one another I want to superimpose these 2 graphs, having them share the same X axis (time) but have 2 different Y axis.

This exercise is possible for graphs, but when done with 2 multigraphs it is impossible since the X ranges diverge. For my case, using 2 graphs is impossible because in-face I am not talking about 2 sensors but 2 groups of sensors: one group plotted in one multigraph and another plotted in the second.

This is a very basic demand that can be done with any graphing tool.

Example:

{
   TCanvas *c = new TCanvas("c","multigraphs on same pad",200,10,700,500); 
   TPad *pad1 = new TPad("pad1","",0,0,1,1);
   TPad *pad2 = new TPad("pad2","",0,0,1,1);   


   float x1[] = {1,2,3}; float y1[] = {4,7,6};
   float x2[] = {3,5,6}; float y2[] = {0,9,4};
   float x3[] = {70,80,90}; float y3[] = {10,20,40};
   float x4[] = {10,60,50}; float y4[] = {50,20,70};

   TGraph *gr1 = new TGraph(3,x1,y1);
   TGraph *gr2 = new TGraph(3,x2,y2);
   TGraph *gr3 = new TGraph(3,x3,y3);
   TGraph *gr4 = new TGraph(3,x4,y4);
   gr3->SetLineColor(kRed);
   gr4->SetLineColor(kRed);

   // Draw the 1st TMultiGraph
   pad1->Draw();
   pad1->cd();   

   TMultiGraph *mg1 = new TMultiGraph();
   mg1->Add(gr1);
   mg1->Add(gr2);
   mg1->Draw("AL"); 

   // Draw the 2nd TMultiGraph
   pad2->SetFrameFillStyle(0);
   pad2->SetFillStyle(4000);
   pad2->Draw();  
   pad2->cd();    

   TMultiGraph *mg2 = new TMultiGraph();
   mg2->Add(gr3);
   mg2->Add(gr4);
   mg2->Draw("AL"); 

   // Draw the axis of the 2nd TMultiGraph
   TAxis *mg2Xaxis = mg2->GetHistogram()->GetXaxis();
   TAxis *mg2Yaxis = mg2->GetHistogram()->GetYaxis();
   Double_t xmin = mg2Xaxis->GetXmin();                       
   Double_t xmax = mg2Xaxis->GetXmax();
   Double_t ymin = mg2Yaxis->GetXmin();
   Double_t ymax = mg2Yaxis->GetXmax();
   mg2Xaxis->SetLabelSize(0);
   mg2Xaxis->SetTickLength(0);
   mg2Yaxis->SetLabelSize(0);
   mg2Yaxis->SetTickLength(0);
   TGaxis *yaxis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,510,"+L");     
   TGaxis *xaxis = new TGaxis(xmin,ymax,xmax,ymax,xmin,xmax,510,"-L");
   xaxis->SetLabelColor(kRed);      
   xaxis->Draw(); 
   yaxis->SetLabelColor(kRed);
   yaxis->Draw();
}


1 Like

Works like a charm. Many thanks!

Just a general question: why are you getting the X/Y axis via the histogram and not directly from the multigraph?

It is similar to:
root.cern.ch/root/html/src/TMult … tml#MUXDrB