TMultiGraph axis

Hi all,

I’m trying to understand why it is that when drawing TMultiGraph, I need to first draw it in order to be able to change its axis.

When doing:

TMultiGraph mg;
TGraph g(10);
mg.Add(&g);
TAxis* axis = mg.GetXaxis(); // returns 0x0

But if I draw mg before I get the axis, it works fine.
When using a simple graph, I don’t have this problem.

Is there any easy way of setting the axis before drawing it?

Cheers,
N.

The axis are created at drawing time. It is even recommended to do:

mg->Draw();
gPad->Update();

I’m aware of what is recommended to do - I am wondering why, especially when contrasted with the TGraph that works well.

When creating a structured program, I want to set the TMultiGraph axis in the same function that handles its data and creates it. This means that I am forced to draw this MultiGraph on some temp canvas, manipulate its axis, then dump the canvas. Then, much later, draw the MultiGraph on its final intended canvas. Also it creates a lot of confusion when the active canvas at the time of running the MultiGraph function gets drawn on.

TMultiGraph is a collections of TGraphs. A TGraph can be added at any time in a TMultigraph, therefore the axis limits computation is done at painting time as you can see here:
root.cern.ch/root/html/src/TMult … tml#n4V_GD

I know this is an old post, but this has been bugging me too. I often want to return a graph from a class containing data. Then plot the graphs from the interpreter or a macro. But I would like to set up the whole plot from the member function. It would be nice to build the axis without drawing. I suppose that’s just the way it is though.

Elliott

Yes the axis limits are compute had drawing time in The method TMultigraph::Paint.
An histogram is created to define the frame. It can be retrieve using GetHistogram().