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);
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?


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


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: … 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.


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().