How can I use SetFillColorAlpha with a TColor?


_ROOT Version: 6.19
_Platform: OS 10.14.3


Hello, I’m plotting this: results2.pdf (29.6 KB) and I want to improve it.

What I want to do is to give each histogram the same transparency and have each histogram get progressively bluer, that way it will be easy to see when the histograms overlap and when they don’t.

To do this I made this:

step = 0.1 #this can be changed depending on how many histograms there are
for n in range(0,allHist):
     colors[n] = TColor(TColor.GetFreeColorIndex(),0,0,n*step)

and it works, then I want to do something like this:

for n in range(0,allHist):
     hist.SetFillColorAlpha(color[n],t) #t is the transparency

BUT when I try to run my code python complains that

TypeError: void TAttFill::SetFillColorAlpha(short fcolor, float falpha) =>
could not convert argument 1 (short int conversion expects an integer object)

And this is the problem.

For a second I thought that maybe I could use the ColorIndices, but I can’t find in the TColor documentation a method that returns you the ColorIndex of a TColor, but even if I could do that, I don’t think SetFillColorAlpha works like that, but, there must be a way to do this, right?

1 Like

You can use TColor::GetNumber to get the color number:

for n in range(0, allHist):
     hist.SetFillColorAlpha(color[n].GetNumber(), t)

The error is because colors[n] has type TColor, and the function expects to receive the color by number. The other possibility is that in the first loop you save the index you receive with TColor.GetFreeColorIndex() in another variable and use it in the call to SetFillColorAlpha instead of colors[n].

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