Colour palette for periodic z-axis

Hello Everyone

I’m trying to plot phase motion in a 2-dimensional space.

As you can imagine, for phases at the extremes (close to +/- 180 degrees) in adjacent bins, the resulting picture is quite visually jarring as the colours also jump rapidly between the extreme ends of their scale despite only being separated by a few degrees in reality.

Looking through the colour palettes in

I couldn’t really find a colour palette that would suit periodic z-axes, so I was wondering if there was maybe an option to somehow combine a particular palette with its inverse or if anyone knows of a possible workaround for this?

You can try creating your own colour palette, ensuring that the last point on the scale is the same colour as the first one. See the CreateGradientColorTable example in the “Color palettes” section on the page you linked. Based on the example there, you could have:

{
   TCanvas *c2  = new TCanvas("c2","c2",0,0,600,400);
   TF2 *f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   const Int_t Number = 4;
   Double_t Red[Number]    = { 1.00, 0.00, 0.00, 1.00};
   Double_t Green[Number]  = { 0.00, 1.00, 0.00, 0.00};
   Double_t Blue[Number]   = { 0.00, 0.00, 1.00, 0.00};
   Double_t Length[Number] = { 0.00, 0.33, 0.66, 1.00};

   Int_t nb=50;
   TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
   f2->SetContour(nb);
   f2->SetLineWidth(1);
   f2->SetLineColor(kBlack);
   f2->Draw("surf1z");
   return c2;
}

which starts and ends on red.

Thanks for your help @dastudillo, I’ll give it a go.

By the way, I’m not sure if this is the right place for a feature request, but if there was an option to maybe append a predefined colour palette to its inverse or vice versa in order to have a more periodic-friendly colour scale, that would be great.

I’m not a ROOT developer, but I suppose one of them may look at your request, or perhaps you can create a new post with the request and see.
As for the idea of appending the inverse palette, I had actually first thought of something similar, where instead of appending another palette, you could just take the bin contents of your final histogram (I suppose it’s a 2D histo) and make a new one in which the midpoint (of the maximum value of bincontents) becomes the new maximum; for bin contents above the midpoint you use a “mirrored” value (from the midpoint); e.g. if the scale goes from 0 to 100, you make it so that after 50 you start going back to zero (using x’ = 100 - x instead of x). But the problem with these ideas is that you will be using the same colours twice, for values before and after the midpoint (e.g. 70 will look the same as 30 in my example), and thus will not be able to differentiate them.

A such functionality is not needed as you can create your own palette the way you like as shown by @dastudillo.

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