TMultiGraph Rescale

Hi,
As I add a TGraph to a TMultiGraph and draw it, I dont see a rescaling of the axis. Is there something that is missing in the code:

  Mg[CanNum][ui.LayerNum->value()]->Add(hp,Gr.data()); 
  Canvas[CanNum]->Update();
  Mg[CanNum][ui.LayerNum->value()]->Draw();
 Canvas[CanNum]->Update();

Thanks,
dsmcc.

Sorry,
I left out the “A” option while drawing. But now I have another problem that as I add a new TGraph, the new axis is overlapping over the old axis markings. Can I have it so that the axis is rescaled to have a single axis marking.
thanks,
dsmcc

Can you send a small running macro reproducing the problem ?

Hi,
Sorry once again, Im back to square one, the rescaling does not work. here is the latest piece of code. Here is what I do:

a) I check if the pointer to TMultigraph is NULL (to see if its already exisiting)
b) if NULL then I create one (else use the existing one)
c) Set Options for the graph
d) Add the Graph to the Multigraph
e) draw

At this point, If the latest added graph is outside the current MultiGraph limits, the axis is not rescaled. Should I do it manually by getting the limits and setting them?

if(Mg[CanNum][ui.LayerNum->value()]==NULL||(!ui.simpose->isChecked())){
	Mg[CanNum][ui.LayerNum->value()] = new TMultiGraph();
	}
	hp->SetName(PNum.data());
	hp->SetMarkerStyle(ui.mstyle->value());
 	hp->SetMarkerColor(ui.mcolor->value());
	hp->SetMarkerSize((ui.msize->value())/5);
	hp->SetLineWidth(ui.linewidth->value());
 	hp->SetLineColor(ui.linecolor->value());
	hp->SetLineStyle(ui.linestyle->value());
	hp->GetXaxis()->SetTitle(XTitle.data());
	hp->GetYaxis()->SetTitle(YTitle.data());
        hp->SetTitle(Titles.data());

	Mg[CanNum][ui.LayerNum->value()]->Add(hp,"P");
	Mg[CanNum][ui.LayerNum->value()]->Draw("A");
	Canvas[CanNum]->Update();
        
        Mg[CanNum][ui.LayerNum->value()]->GetXaxis()->SetTitle(XTitle.data());
	Mg[CanNum][ui.LayerNum->value()]->GetYaxis()->SetTitle(YTitle.data());
thanks,

dsmcc

Your example cannot be run. Here is a running example. I hope it will help:

{
   TGraph *g[3];
   Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
   Double_t y[10] = {1,2,3,4,5,5,4,3,2,1};
   TMultiGraph *mg = new TMultiGraph();
   for (int i=0; i<3; i++) {
      g[i] = new TGraph(10, x, y);
      g[i]->SetMarkerStyle(20);
      g[i]->SetMarkerColor(i+2);
      for (int j=0; j<10; j++) y[j] = y[j]+1;
      mg->Add(g[i]);
   }
   mg->Draw("AP");
}