Using the bookmarked conversation mentioned in this answer, I was able to extract the colors (and their parametric positions) of the Mathematica color scheme BrightBands
Cases[ColorData[{"BrightBands", "Reverse"}], {a_?NumericQ,
x_RGBColor} -> {1 - a, x}, inf]
resulting in$^1$
fig1.
Notice how the positions are 1/(noOfColors-1)
apart. This is true for all other color schemes (in "Gradient") too.
Using linear interpolation between these colors$^2$ at those positions, I was able to reproduce the color scheme in Java (a different programming language), all except for "BrightBands" and "DarkBands", that is.
While for every other scheme the interpolation works as intended, it's too continuous for these two banded color schemes:
My reproduction
vs
Mathematica's actual rendering
As is clearly seen, linear interpolation doesn't 'band' like in Mathematica's rendering.
- How to achieve this?
FAQs
Are you sure its not a coding problem at your end?
Yes. For all other gradients that don't involve bands, I am able to reproduce the Mathematica gradients.
Did you investigate further?
Of course, though I am not sure if these observations are of any help.
- Let
cd=ColorData@"BrightBands"
. The behavior expected on the basis of a linear interpolation is that on $[1/11,2/11]$, the color should change smoothly from pink (second entry of the array shown in fig1 ) to purple (third entry). Instead it switches abruptly near $\approx 0.15293(1)$, about 68% percent of the way. - The difference between the colors of
ColorData@"scheme"
andColorData@{"scheme","Reverse"}
is $0$ except for the banded color schemes
cls=ClearAll;
lgrid = Grid[#1, Alignment -> Left] &
(*extract color info*)
cls@getCols;
getCols[scheme_String] :=
Cases[ColorData[{scheme, "Reverse"}], {a_?NumericQ,
x_RGBColor} -> {a, x}, inf]
(*produce the difference in colors*)
cls@findDiffs;
findDiffs[scheme_String] := Module[{cd, cdr, cols, colsr, n, diff},
cd = ColorData@scheme;
cdr = ColorData@{scheme, "Reverse"};
colsr = getCols[scheme][[;; , 2]];
n = len@colsr - 1;
cols = cd /@ Range[0, 1, 1/n];
diff = List @@@ colsr - List @@@ cols
]
(*tabulate them*)
Module[{names = ColorData@"Gradients"},
{#, findDiffs@# // Flatten // Abs // Total} & /@ names
] // lgrid
resulting in $$ \begin{array}{ll} \text{AlpineColors} & 0. \\ \text{Aquamarine} & 0. \\ \text{ArmyColors} & 0. \\ \text{AtlanticColors} & 0. \\ \text{AuroraColors} & 0. \\ \text{AvocadoColors} & 0. \\ \text{BeachColors} & 0. \\ \text{BlueGreenYellow} & 0. \\ \text{BrassTones} & 0. \\ \text{BrightBands} & 2.26287 \\ \text{BrownCyanTones} & 0. \\ \text{CandyColors} & 0. \\ \text{CherryTones} & 0. \\ \text{CMYKColors} & 0. \\ \text{CoffeeTones} & 0. \\ \text{DarkBands} & 2.5635 \\ \text{DarkRainbow} & 0. \\ \text{DarkTerrain} & 0. \\ \text{DeepSeaColors} & 0. \\ \text{FallColors} & 0. \\ \text{FruitPunchColors} & 0. \\ \text{FuchsiaTones} & 0. \\ \text{GrayTones} & 0. \\ \text{GrayYellowTones} & 0. \\ \text{GreenBrownTerrain} & 0. \\ \text{GreenPinkTones} & 0. \\ \text{IslandColors} & 0. \\ \text{LakeColors} & 0. \\ \text{LightTemperatureMap} & 0. \\ \text{LightTerrain} & 0. \\ \text{MintColors} & 0. \\ \text{NeonColors} & 0. \\ \text{Pastel} & 0. \\ \text{PearlColors} & 0. \\ \text{PigeonTones} & 0. \\ \text{PlumColors} & 0. \\ \text{Rainbow} & 0. \\ \text{RedBlueTones} & 0. \\ \text{RedGreenSplit} & 0. \\ \text{RoseColors} & 0. \\ \text{RustTones} & 0. \\ \text{SandyTerrain} & 0. \\ \text{SiennaTones} & 0. \\ \text{SolarColors} & 0. \\ \text{SouthwestColors} & 0. \\ \text{StarryNightColors} & 0. \\ \text{SunsetColors} & 0. \\ \text{TemperatureMap} & 0. \\ \text{ThermometerColors} & 0. \\ \text{ValentineTones} & 0. \\ \text{WatermelonColors} & 0. \\ \end{array} $$
Praise for the answers
(as on September end '21)
Its a shame that I can't accept multiple answers. All three answers - one each from Domen, N.J.Evans and kglr - helped solved my question, especially the first two.
Domen's answer made me realize that Cases
wasn't extracting all the information for the banded color schemes and Mr.Wizard's was the way. He also showed that the interpolation was linear after all, just discontinuous. The DataPaclets'
result explicitly showed the position repetition at discontinuity.
N.J.Evans rightly pointed out that this was an expected behavior of Blend
and was documented in its 'Possible Issues' section.
kglr summed up the efforts by providing direct one-liners that extracted the relevant info. He also highlighted that the reverse blend isn't using 1-#
positions.
Besides, they (Domen and kglr) also established Blend
as being the underlying blending mechanism in ColorData
.
Appendix
$^1$ with InputForm
{{0., RGBColor[0.90222, 0.101808, 0.198306]},
{0.09090909090909094, RGBColor[1., 0.602487, 0.750759]},
{0.18181818181818188, RGBColor[0.400595, 0.302083, 1.]},
{0.2727272727272727, RGBColor[0.80061, 0.74902, 0.999603]},
{0.36363636363636365, RGBColor[0.104631, 0.700359, 1.]},
{0.4545454545454546, RGBColor[0.65277, 0.932433, 1.]},
{0.5454545454545454, RGBColor[0.205646, 0.965652, 0.0889754]},
{0.6363636363636364, RGBColor[0.722118, 1., 0.558145]},
{0.7272727272727273, RGBColor[0.972274, 0.938231, 0.192309]},
{0.8181818181818182, RGBColor[1., 0.976715, 0.598215]},
{0.9090909090909092, RGBColor[1., 0.500511, 0.000244144]},
{1., RGBColor[1., 0.749752, 0.501183]}}
$^2$ By this we mean that first the parameter space $[0,1]$ of the argument of ColorData
, say $t$, is divided into $[x_i,x_{i+1}]$ intervals where $x_i$ are the color positions of the colors in that scheme. Then as $t$ varies over $[x_i,x_{i+1}]$, the color varies over $(1-\alpha)\text{color}_i+\alpha~ \text{color}_{i+1}$, where $\alpha$ is a linear function of $t$ that varies over $[0,1]$