Persitifying Hex Colors

I often use hexadecimal color codes and convert them to TColor using TColor::GetColor (const char *hexcolor) [1] for coloring TH1, TGraph, etc. However, when I store the histograms or graphs in a root file and try to draw them later, they appear invisible, i.e. the color is forgotten. How can I make sure that the color is also stored in the root file and used automatically?

ROOT Version: 6.14/09

[1] ROOT: TColor Class Reference

Yes, colors are not stored in ROOT file. You should redefine them. Usually it is done in rootlogon.C.

Is there a more flexible/portable/shareable/self-contained version of this? i.e. not sending everyone your rootlogon.C file so they can work with the same plots.

Not really. The Colors are not stored on purpose. They might be a lot of them and we cannot afford storing them in the root file. Colors should be redefined.

Thanks for the replies. If storing colors is not an option, could ROOT be updated to not make graphs/histograms invisible after storing to file?

Invisible ? can you provide an example ?

Sure.

Using ROOT 6.24/01, I make a histogram, create TColor from hex code, draw it (color works), and store it to a file.

root [0] TH1F h(“h”,"",100,-5,5)
root [1] h.FillRandom(“gaus”,50000)
root [2] Int_t col = TColor::GetColor("#c53a48")
root [3] h.SetLineColor(col)
root [4] h.Draw(“hist”)
root [5] TFile f(“test_color_visibility.root”,“RECREATE”)
root [6] f.cd()
root [7] h.Write()
root [8] f.Close()
image

I close the ROOT session, start a new one, open the file, and draw the histogram: histogram is invisible.

HunterBidenLaptop@2019:~ root test_color_visibility.root
root [2] h->Draw(“hist”)
image

with ROOT master (6.26) I get:

% root -l test_color_visibility.root
root [1] h->Draw()

Indeed it depends if the color you get in the initial macro is defined (not white) or not.

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