Problem passing list in TAxis constructor with pyroot

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


I am making a list of the bins I want to create, but when trying to set the bins via the TAxis I get errors. My code is like this

    AXISBINS =[]
    for i in range(0, NPOINTS):  AXISBINS.append (graph.GetX()[i] - graph.GetErrorXlow(i))

    AXISBINS.append( graph.GetX()[NPOINTS-1] + graph.GetErrorXhigh(NPOINTS-1))
    [float(i) for i in AXISBINS]
    graph.GetXaxis().Set(int(NPOINTS), AXISBINS)

the error I get is the following

graph.GetXaxis().Set(int(NPOINTS), AXISBINS)
TypeError: none of the 3 overloaded methods succeeded. Full details:
void TAxis::Set(int nbins, double xmin, double xmax) =>
takes at least 3 arguments (2 given)
void TAxis::Set(int nbins, const float* xbins) =>
could not convert argument 2
void TAxis::Set(int nbins, const double* xbins) =>
could not convert argument 2

OK, I found the solution to my problem. One should do

AXISBINSS = array(ā€˜dā€™)

instead of


Hi @Alkass,

Indeed, if C++ expects a double*, array.array (or numpy.array) of doubles is the way to go.


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