# Inverted Color Palettes

**URL:** <https://root-forum.cern.ch/t/inverted-color-palettes/24826>\
**Category:** ROOT\
**Tags:** hist\
**Created:** [May 19, 2017, 5:44pm UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826 "2017-05-19T17:44:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [May 19, 2017, 5:44pm UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/1 "2017-05-19T17:44:13Z")

</div>

Hi,

Is it possible to easily invert the predefined color palettes? There are some great palettes predefined, but in my opinion they are defined backwards. For example, `kCherry` runs from black to white through red. This looks good for 3D renderings, but is confusing for 2D histograms rendered with the `"COLZ"` option as empty bins (or those below the minimum) and the maximum bins are nearly the same color. I’d like the colors to run from white to black through red. This is true for many others as well: `kGreyScale`, `kCoffee`, `kPigeon`, _etc_. In general it would easily “double” the available number of palettes.

It would be nice if it was as simple as:

```auto
gStyle->SetPalette(kCherry);
gStyle->InvertPalette();

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 22, 2017, 7:24am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/2 "2017-05-22T07:24:35Z")

</div>

That’s a matter of taste… There is no such functionality right now.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [May 22, 2017, 6:23pm UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/3 "2017-05-22T18:23:52Z")

</div>

Wasn’t so hard once I figured out what was going on in `TColor`.

Would this [commit](https://github.com/ksmith0/root/commit/37824b29d48ea9c3af22571923d9db02cddd6a54) be appreciated as a pull request?

A short demonstration:

```auto
{
   gStyle->SetPalette(kCherry);
   TColor::InvertPalette();

   TF2 *f = new TF2("xygaus", "xygaus", -2, 2, -2, 2);
   f->SetParameters(1,0,1,0,1);

   TH2D* h = new TH2D("h", "H", 50, -2, 2, 50, -2, 2);
   h->FillRandom("xygaus", 50000);
   h->Draw("COLZ");
}

```

 ![](https://root-forum.cern.ch/uploads/default/original/2X/2/21229b18d7cf6916395fde45f8df28c393920057.png)

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [May 22, 2017, 6:42pm UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/4 "2017-05-22T18:42:13Z")

</div>

I ran the `palettes.C` tutorial as well (with the additional `TColor::InvertPalette()` line) to give a nice comparison between inverted palettes and the [regular](https://root.cern.ch/doc/master/classTColor.html#C06) ones, but I can’t upload pdfs here. So I attached a couple examples instead.

Here is the plot for `kCherry`:  
 ![](https://root-forum.cern.ch/uploads/default/original/2X/e/e71d21e0e93c4f48bb0f1a9280695fc10f478d9d.png)

Here is the plot for `kGreyScale`:  
 ![](https://root-forum.cern.ch/uploads/default/original/2X/9/9145d67bbfca3297a5588f38cd9e5b7b5af8f959.png)

Here is the plot for `kBird`  
 ![](https://root-forum.cern.ch/uploads/default/original/2X/5/5f65c36b3c3e73f6cddfc2610b48860bca5af870.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 23, 2017, 7:57am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/5 "2017-05-23T07:57:30Z")

</div>

Many thanks for you contribution. Yes that’s not to hard to implement. I will take your code.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 23, 2017, 8:58am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/7 "2017-05-23T08:58:16Z")

</div>

Now in place. Thanks for the suggestion.

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [May 23, 2017, 9:07am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/8 "2017-05-23T09:07:38Z")

</div>

In the documentation you added, " The top of the palette becomes the bottom et vice versa." should read " The top of the palette becomes the bottom **and** vice versa."

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 23, 2017, 9:09am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/9 "2017-05-23T09:09:09Z")

</div>

Thanks to have seen it so quickly. Fixed

---

<div class="post-metadata">

**Author:** ![pamputt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pamputt/32/12526_2.png) [@pamputt](https://root-forum.cern.ch/u/pamputt)\
**Post date:** [May 23, 2017, 9:11am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/10 "2017-05-23T09:11:43Z")

</div>

It also has to be fixed in the documentation of the InvertPalette method 😉

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 23, 2017, 9:14am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/11 "2017-05-23T09:14:14Z")

</div>

Damned you are right ! 🙂 Done… thanks,

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 6, 2017, 9:14am UTC](https://root-forum.cern.ch/t/inverted-color-palettes/24826/12 "2017-06-06T09:14:16Z")

</div>

Closed on June 6, 2017, 9:14am UTC

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