Feature Request: Transform TAxes

It has come up many times now for myself and others (and you can see by searching RootTalk) that we need to “rescale” an axis somehow. I don’t mean to change the actual values underneath, but somehow transform the labels which appear on the axis.

It would be very convenient if there was a way to do the following:

  1. define either a C++ function or a TF1 which takes as the argument the original axis values and returns the transformed valued
  2. pass this function/functor/thing to a TAxis method
  3. magically see the axis labels transformed when the gPad is updated.

This would allow users to for example change the units on their TGraphs and TH* without actually changing the underlying object. It would allow remapping to arbitrary non-linear axes. It looks like there is such a method for TGaxes but it is absolutely not clear how to use this for the axis of an existing object (which is a TAxis, not a TGaxes, and they seem to be only distantly related classes).

If this would somehow break the TAxis implementation, I could request a much more modest feature. A TAxis method taking two arguments: a shift and a scale factor. Then one could apply arbitrary affine transformations to their axes (allowing most unit transformations) again without changing the underlying data.

If there is currently a way to accomplish this, I would be very happy to learn of it. I hope I don’t just get reasons why this is impossible.


The TGaxis method is not meant for that purpose. TGaxis is only the “axis painting” class and does not know about the data stored in a histogram or in a graph.

What you request here implies the transform function will also be applied on the histogram (or graph) data. There is no “magic” (as suggested in your point 3) ).

I think all the tools are here to do something like that. You simply need to make a procedure which create a new histogram or graph from the existing one but with the new axis. This procedure will need to do the transformation on data also.

This has the advantage that you can keep (or not) the original data.

Of course this can be discussed.

I’d like to backup Jean-François’s proposal.

The current TGaxis is a simple toy which is useful in some very limited simple cases (btw. that’s nowhere really described so people try to utilize it also for more complex cases -> then one gets reports that the new axis labels do not correspond to the function that defines the axis’s transformation and/or to the drawn histogram / graph).

For the moment, one needs to “scale” the axes values of ones histogram -> see the “Can we shift histogram for several channels?” thread: [url]Can we shift histogram for several channels?

Agreed that’s what I said before: TGaxis is only the painter of the real axis: TAxis.

Jean-François’s proposal can be implemented right now using the existing tools (as in the thread you pointed), or can be done inside THx et TGraphx. I am not sure it can be done in TAxis itself as the data must be changed too.

May be Lorenzo can comment …

The thread that I pointed to is also limited to some simple cases. It directly modifies the histogram (and that means that one would need to modify all histograms / graphs that one wants to draw). In general, this is not desired, I believe.

I think one really needs a TGaxis class which is able to draw ticks and labels according to an “arbitrary”, user defined, function.