TGraph SetLimits

_ROOT Version: 6.14
_PYTHON Version : 3.6.7
_Platform: Debian 9
_Compiler: GCC 7.3.0

Hi, I frequently use the method below to reassign the axes of a square 2D histogram with physical units (in this case pixels are converted to mm)

def PixToMM(h1): 
    sizeAxis = h1.GetXaxis().GetNbins()
    dimensions = ((sizeAxis-2)/43.5)*0.474*m
    h1.GetXaxis().SetLimits(0., dimensions)
    h1.GetYaxis().SetLimits(0., dimensions)

When I try a similar method for a TGraph object, it does not work as I wished it would. SetLimits() for the TGraph Object behaves like SetRangeUser() for a histogram.

Here, some pseudo code to illustrate what I mean :

bin_number = tgraph.GetXaxis().GetNbins() 
dimensions = ((bin_number-2)/43.5)*0.474*m 
tgraph.GetXaxis().SetLimits(0., dimensions)  ---> This line behaves as SetRangeUser() normally does.

Do you have any suggestions how to convert the x-axis from pixels to mm if SetLimits does not work here?


For TGraph, GetXaxis() returns sth defined here

It returns a histogram

I’m not a frequent user of SetLimits, but when I draw with TGraph, I always first draw a TH1 myself, then I manipulate the TH1 for everything, just because I’m more familiar with THistogram’s behavior.

There is an HowTo about his:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.