Create a text file (e.g. “mycolours.txt”) with the RGB values (one colour per line, R G B separated by space) and use TColor::CreateColorTableFromFile
#include <TStyle.h>
#include <TFile.h>
#include <TH2F.h>
void p3_draw() {
const int n = 6;
Int_t MyPalette[n];
Int_t FI = TColor::CreateColorTableFromFile("mycolours.txt");
for (int i = 0; i < n; i++)
MyPalette[i] = FI + i;
gStyle->SetPalette(n, MyPalette);
gStyle->SetNumberContours(n);
gStyle->SetOptStat(0);
TH2F* h2 = new TH2F("h2", "skymap", 100, -180, 180, 100, -90, 90);
h2->Fill(0., 0., 100.0);
h2->Fill(10, 100, -9100);
h2->Fill(20, -100, 10000);
h2->Fill(-20, 30.0, 6000);
h2->Fill(-60., 0., 1000);
h2->GetZaxis()->SetRangeUser(0, 6000);
h2->Draw("colz");
}
$ cat mycolours.txt
0.8 0.8 0.8
1.0 0.0 1.0
1.0 0.5 0.0
0.0 0.0 1.0
0.0 1.0 0.0
1.0 0.0 0.0