TGraph range in TMultiGraph


I’m trying to plot several TGraphAsymmError with different ranges into one canvas. I’ve used a TMultiGraph to do so, but it plots always the full range.

mg = TMultiGraph()
for i in bla:
    h1 = TGraphAsymmErrors()
    h1.Divide(htest[i],href[i],"cl=0.683 b(1,1) mode")
    h1.Draw("AP")  #<- Plots the correct range
mg.Draw("AP") #<- Plots full range

I’ve also tried to get the Taxis from the TGraphAsymmError and apply SetLimits. But again no changes in the resulting plot.



Here is an example I had doing that:

   int     N     = 10;
   double* S_Eff1 = new double[N];
   double* B_Eff1 = new double[N];
   double* S_Err1 = new double[N];
   double* B_Err1 = new double[N];

   double* S_Eff2 = new double[N];
   double* B_Eff2 = new double[N];
   double* S_Err2 = new double[N];
   double* B_Err2 = new double[N];

   for(int i=0;i<N;i++){
      S_Eff1[i] = 3*pow(1.5,-1*i);
      B_Eff1[i] = 1*pow(10,-1*i);
      S_Err1[i] = 0.01 * pow(10,-1*i);
      B_Err1[i] = 0.01 * pow(10,-1*i);

      S_Eff2[i] = 3*pow(1.2,-1*i);
      B_Eff2[i] = 1*pow(3,-1*i);
      S_Err2[i] = 0.01 * pow(3,-1*i);
      B_Err2[i] = 0.01 * pow(3,-1*i);

   TGraphErrors* Discrim_Same = new TGraphErrors(N, B_Eff1, S_Eff1, B_Err1, S_Err1);

   TGraphErrors* Estim_Same = new TGraphErrors(N, B_Eff2, S_Eff2, B_Err2, S_Err2);

   TCanvas *c1 = new TCanvas("c1","c1",800,600);

   TMultiGraph* mg1 = new TMultiGraph();
   mg1->Add(Estim_Same  , "PL");
   mg1->Add(Discrim_Same, "PL");



Thanks a lot for the answer. But I think I didn’t clearly say what my problem is.

I want different ranges for different TGraphasymmErrors in the TMultigraph.

I.e. I have several TGraph, initially reaching from 0 to 2000. Now I want to plot graph 1 only from 0 - 100, graph 2 from 50 - 500, graph 3 from 250 - 100 and so on.

So not one range for all, but a specific range for every TGraph in the TMultiGraph.

And what do you want to get at the end? What is the range that you expect for your TMultiGraph?

Sorry for the poor description. Perhaps an example could help.
Have a look at the attached plot.
The range of the canvas is fine. But I want e.g. the red crosses (markerstyle 3) to start at 200 and be plotted up to 800.
The blueish stars should go from 120 to 800 and the empty crosses should go from 80 - 800.
EffCombined.pdf (48.2 KB)

In that case the graph with red-cross you put in the TMultiGraph should start at 200 and finish at 800.
Make a “sub graph” before putting it in the multigraph.


how do I produce such a subgraph?
I’ve tried to set the range of the Histograms used to make the TGraph (the ones from Divide(a,b, opt)), setting the limits of the TGraph, the range of the underlying histogram (via gr->getHistogram() ), changing the range of the x-axis…
Everything seems to reset as soon as I call multigraph->Add()
The only way I could think of is setting the values to 0… Which is not a very elegant way to do it…

You make a new graph and you copy only the points you need from the 1st graph into it (using a “for” loop).

Ok thanks. I’ll do it that way.

Hi all,

Has there since been a more elegant solution to this problem? I have the same exact problem and would like to keep it simple, without having to create a new graph through a for loop at least?


The method to produce a subgraph is still the one mentioned before. I do not think we can make it simpler. Do you have some suggestion ?