# How to set color with \`gStyle-\>SetPalette\` for first bin and last bin? may be bugs

**URL:** <https://root-forum.cern.ch/t/how-to-set-color-with-gstyle-setpalette-for-first-bin-and-last-bin-may-be-bugs/59457>\
**Category:** ROOT\
**Created:** [May 25, 2024, 1:16am UTC](https://root-forum.cern.ch/t/how-to-set-color-with-gstyle-setpalette-for-first-bin-and-last-bin-may-be-bugs/59457 "2024-05-25T01:16:43Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 25, 2024, 6:33am UTC](https://root-forum.cern.ch/t/how-to-set-color-with-gstyle-setpalette-for-first-bin-and-last-bin-may-be-bugs/59457/6 "2024-05-25T06:33:26Z")

</div>

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](https://root.cern/doc/master/classTColor.html#a8b075c0f885fe2e672b68d06ed966f6c)

```auto
#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");
}

```

```auto
$ 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

```

 ![c1](https://root-forum.cern.ch/uploads/default/original/3X/6/5/65799f1b5b10b7092642180e7dd6db97c6aaf888.png)

---

_[View the full topic](https://root-forum.cern.ch/t/how-to-set-color-with-gstyle-setpalette-for-first-bin-and-last-bin-may-be-bugs/59457)._
