Using colors from color palette

I want to use a color palette and assign the colors to histograms. I cannot assign the same colors from the color palette to two different histograms using the draw option with “PLC”. How to do it?

The documentation indicates that the PLC option provides an automatic way to define colors for the objects inside a pad. Each object gets its own color. If you want to assign the same color to two histograms, you need to set the color of these histograms without using the PLC option.

Thanks for the reply.
I have about 72 histograms, then how to take the 72 colors from any palette, such that it covers all the spectrum colors?

I tried this, but it only shows light and dark blue colors

gStyle->SetPalette(kRainBow);
    int nColors = gStyle->GetNumberOfColors();
    auto palette = TColor::GetPalette();
    for (int i = 0; i < 72; ++i)
    {
        gr[i]->SetLineColor(palette.At(i));
        grclone[i]->SetLineColor(palette.At(i));
    }
void h72() {
   gStyle->SetOptStat(0);
   TH1F *h[72];

   for (int i=0; i<72; i++) {
      h[i] = new TH1F(Form("h%d",i), Form("h%d",i), 72, 0., 71);
      h[i]->Fill(i);
      h[i]->SetFillStyle(1001);
      if (i != 30) h[i]->Draw("same PFC");
   }
   gPad->Update();
   h[30]->SetFillColor(h[0]->GetFillColor());
   h[30]->Draw("same");
}
1 Like

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