Color names in python

hello, I am in lxplus (alma9) and I have an old python script that I used to plot some histograms and diagrams.
originaly I was using “from ROOT import *” but now I’ve got a message saying I need to specify what I want to import. Fine. Now I set it to “from ROOT import TH1, TBox”

This works, but if I try to set the color of the box with
box.SetFillColor(kGray)
the error I get is:
NameError: name ‘kGray’ is not defined.

I tried with “from ROOT import TH1, TBox, TColor”

but it does not work either.

Then I found the same error for the markers: kOpenCircle is not recognized :frowning:

How can I set all the colors and marker styles by name (enum)?

Thanks
Salva


Please read tips for efficient and successful posting and posting code

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


I would use:
box.SetFillColor(ROOT.kGray)
This should work.

Alternatively, try import TH1, kGray, ...

Try importing EColor (defined in ROOT: core/base/inc/Rtypes.h Source File). With ROOT 6.32.08 this works:

>>> from ROOT import TBox, EColor
>>> b = TBox(0.2,0.2,0.5,0.5)
>>> b.SetFillColor(EColor.kTeal)
>>> b.Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
>>> 

Thanks for the tips!

Both of this options work:
from ROOT import TH1, kGray
from ROOT import TBox, EColor

But I recommend the second one (from ROOT import TBox, EColors) as will have all colors in hand.

Thanks
Salva

Hi! FYI, in the upcoming ROOT 6.36, you will be able to simply use strings like "kBlack":