Problem with CreateTransparentColor in pyroot

Hello

I am having the following function in pyroot

import ROOT
def CreateTransparentColor(color, alpha) :
  adapt = gROOT.GetColor(color);
  new_idx = gROOT.GetListOfColors().GetSize() + 1;
  trans = TColor(new_idx, adapt.GetRed(), adapt.GetGreen(), adapt.GetBlue(), "", alpha);
  trans.SetName("userColor%i".format(new_idx))
  return new_idx

However, when I try something like

idX_color = CreateTransparentColor(kGreen,0.3)

I get the following error


ValueError: void TAttFill::SetFillColor(short fcolor) =>
    could not convert argument 1 (integer 64001 out of range for short int)

The same code withe the same input arguments works fine in C++

Any tips ?

TIA

Alexis

It looks like a Python issue. @etejedor may have an idea.

Hi,

How do you call SetFillColor ? That call does not appear in your code, but it seems the one causing the issue.

In any case, it seems that you are calling SetFillColor with an integer (64001) which can’t be represented with type short, which is what SetFillColor expects. Can you check that you are passing the right color value? @couet is 64001 a correct color value?

Color_t is a short. The max short value is 32767. So indeed 64000 is too big. So why, @Alkass, did you say it works with C++ ? it should not … Can you post the C++ version you made ?

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