Set Histogram line color to custom TColor

I am trying to use TH1::SetLineColor in order to color a histogram using a custom color. However, I must be misunderstanding the custom color interface because I do not get the correct color. Run the test() function from the file below to see the result. I would like to know the proper way to use the TColor custom colors to set a histogram line color.

I am using ROOT 5.34/05 and cannot easily upgrade to ROOT 6 on this particular system.

ColorTest.C (180 Bytes)
hist.root (17.5 KB)

three things:

  • use a larger number (at least in ROOT6, 1000 is already assigned)
  • if you create the TColor with automatic storage duration, it is deleted when reaching the closing } of the block. You probably don’t want that, so use TColor *a = new TColor(...);
  • it is not documented (at least I couldn’t find it anywhere), but looking at the examples it seems the RGB values need to be in the range [0,1] (not: [0,255]).


#include <TH1F.h>
#include <TColor.h>

void ColorTest()
  TH1 *h1 = new TH1F("h1","h",3,0,3);
  TH1 *h2 = (TH1*) h1->Clone("h2");
  TH1 *h3 = (TH1*) h1->Clone("h3");

  TColor *c1 = new TColor(9001,1,0.5,0); //is this your color?
  TColor *c2 = new TColor(9002,0,1,0); //green
  TColor *c3 = new TColor(9003,0,0,1); //blue



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