24

Hi I want to get a blend similar to "SunsetColors". To make those slight modifications, I would like to know the precise blend of that color scheme.

My try:

Graphics[Table[{Blend[{Black, RGBColor[0.30, 0, 0.36], 
                       RGBColor[.99, .42, 0], LightYellow}, Sqrt[x]], 
                Disk[{8 x, 0}]}, {x, 0, 1, 1/8}]]

And this is how "SunsetColors" looks like:

Graphics[Table[{Blend["SunsetColors", x], Disk[{8 x, 0}]}, {x, 0, 1, 1/8}]]
rm -rf
  • 88,781
  • 21
  • 293
  • 472
Francisco
  • 609
  • 3
  • 11

2 Answers2

24

It looks like the blend colours can be extracted with:

DataPaclets`ColorDataDump`getColorSchemeData["SunsetColors"][[5]]

(* {RGBColor[0., 0., 0.], RGBColor[0.372793, 0.1358, 0.506503], 
 RGBColor[0.788287, 0.259816, 0.270778], 
 RGBColor[0.979377, 0.451467, 0.0511329], 
 RGBColor[1., 0.682688, 0.129771], RGBColor[1., 0.882236, 0.491094], 
 RGBColor[1., 1., 1.]} *)
Simon Woods
  • 84,945
  • 8
  • 175
  • 324
18

First answer

Ok, Simon Woods killed the fun but I was already wiriting this:

spec = List @@@ Table[ ColorData["SunsetColors", i]
                       , {i, 0, 1, .001}] // Transpose;

ListLinePlot[spec, ImageSize -> 900, PlotStyle -> {Red, Green, Blue}, 
                    BaseStyle -> Thick]

enter image description here

Here we can see how colors are changing across 0-1. It is clearly seen that thare are only a couple of base colors, which are annouced by derrivative change. Let's find those colors.

First, the positions:

change = Accumulate @ (Length /@ 
        (Round[#, 0.000001] & /@ (Subtract @@@ Partition[spec[[3]], 2, 1]) // Split))
(*not very elegant way to find breaks but I'm in hurry*)
{166, 167, 333, 334, 500, 666, 667, 833, 834, 1000}

No need to do this automaticaly so at the end I left:

change = {0, 166, 333, 500, 666, 833, 1000}

And those are our colours:

colors = Blend["SunsetColors", #] & /@ (change/1000)
{RGBColor[0., 0., 0.], RGBColor[0.371302, 0.135257, 0.504477], 
   RGBColor[0.787456, 0.259568, 0.271249], 
   RGBColor[0.979377, 0.451467, 0.0511329], 
   RGBColor[0.999918, 0.681763, 0.129456], 
   RGBColor[1., 0.881837, 0.490371], RGBColor[1., 1., 1.]}
GraphicsGrid[{
          {Graphics[Table[{Blend[colors, x], Disk[{8 x, 0}]}, {x, 0, 1, 1/50}]]}, 
          {Graphics[Table[{Blend["SunsetColors", x], Disk[{8 x, 0}]}, {x, 0, 1, 1/50}]]
             }}, ImageSize -> 900]

enter image description here

Update

Like I've said in comments I think all available color schemes are created via Blend so we do not have to worry about "positions" of each one in color list but the only question is, how many colors are used for each scheme? Then we can take base as sample of equally spaced colors. To prove I'm right:

col = ColorData["Gradients"];

test = {};
Do[
   palette = col[[i]];
   (*following procedure is counting how many lines create given spectrum,
     like in the picture*)
   n = Fold[#2@# &,
            palette,
            {(List @@@ Table[Blend[#, i], {i, 0, 1, .001}])[[;; , 2]] &,
             Round[Differences@#, 10^-6] &,
             Split,
             Length /@ # &,
             Select[#, # > 10 &] &,
             Length
             }];
   basecolors = Blend[palette, #] & /@ Range[0, 1, 1/n]; (*our predictions*)
   realbase = DataPaclets`ColorDataDump`getColorSchemeData[palette][[5]];
   (*real base colors*)
   AppendTo[test, realbase == basecolors]; (*test*)
   , {i, Length@col}];

 test

{True, True, True, True, True, True, True, True, True, False, True, \ True, True, True, True, False, True, True, True, True, True, True, \ True, True, True, True, True, True, True, True, True, False, True, \ True, True, True, True, True, True, True, True, True, True, True, \ True, True, True, True, True, True, True}

There are couple  of Falses, it is because sometimes slopes are so similar that above naive procedure is not able to distinguish them and we end up with underestimated number of lines.

Also if we choose other color to look for lines (*here it is Green, it is set there: [[;; , 2]] *) procedure will fail somewhere else, that's reasonable, it is all because of poor implementation :)

But the point is, my anticipation was correct.

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • Very nice. Perhaps you could add a smooth-curve version of the blend as well? That might be interesting. – Mr.Wizard Aug 15 '13 at 15:02
  • @Mr.Wizard What do you mean? ;) O-C graph between "SunsetColors" and colors? – Kuba Aug 15 '13 at 15:04
  • If the RGB curves were smoothly interpolated it might be interesting to see how the resulting gradient looked beside the built-in one. – Mr.Wizard Aug 15 '13 at 15:06
  • @Mr.Wizard I must say, I don't know what you are asking for. Is higher order interpolation important or relevant somehow? Feel free to edit my answer and add this, this will be faster :) – Kuba Aug 15 '13 at 15:11
  • Never mind; I was just having fun with this. Like I said, nice answer. – Mr.Wizard Aug 15 '13 at 15:13
  • Nicely done, and without resorting to undocumented functions... – Simon Woods Aug 15 '13 at 15:13
  • @SimonWoods Thanks, it is good to know undocumented functions too, I will use yours next time :) – Kuba Aug 15 '13 at 15:22
  • Nice. I can't visually distinguish between Blend["SunsetColors"] and yours, +1. :) – rcollyer Aug 15 '13 at 16:11
  • @rcollyer thanks :) I think I did too much calculations. Those palletes seems to be produced by given set of colours to Blend in straightforward way so we need only to know that there are n colors and take the step 1/(n-1) to get those base colors. I will add this remark to the answer soon. – Kuba Aug 15 '13 at 16:18
  • by the way, you might be able to use Differences to simplify some of the code – amr Aug 15 '13 at 18:19
  • @rcollyer now they are exactly the same :) – Kuba Aug 15 '13 at 18:55
  • @amr yes, you're right. I used it in update insted of Subtract – Kuba Aug 15 '13 at 18:56
  • @Kuba I mentioned that you couldn't visually tell them apart because without testing, it was good enough. Making them exactly the same, even better! – rcollyer Aug 15 '13 at 19:07
  • @rcollyer I know, I know, I just had to finish this :P – Kuba Aug 15 '13 at 19:09