How to get a scaled density plot for a custom color function? [closed]

I have considered 12 major colours to design my custom colour function.

colors = {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink,
Cyan, Yellow, White};


I've sorted them based on their corresponding grey values using the formula: value = 0.2989 * Red + 0.5870 * Green + 0.1140 * Blue

and I have got the corresponding values:

positions = {0.0000, 0.1140, 0.20645, 0.2989, 0.43694, 0.50000,
0.5870, 0.5924, 0.6494, 0.7010, 0.8859, 1.0000};


When I plot the colour values as a density plot, I get the following

But I want to use the positions as well to get the 12 colours at those positions in a 0 to 1 scale and the rest of the values should get interpolated accordingly.

How can I do this?

• Have you noticed Blend?
– Johu
Feb 17 '17 at 13:21
• Does this helps: Plot[Sin[x], {x, -Pi, +Pi}, PlotStyle -> Directive[Orange, Thick, Dashed], ColorFunction -> (Blend[colors, #] &)]
– mrz
Feb 17 '17 at 13:38

Blend

colors =
{Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

w = List @@@ ColorConvert[colors, "RGB"] . {0.2989, 0.5870, 0.1140}

colorfn = Evaluate[Blend[{w, colors}\[Transpose], #]] &;

DensityPlot[x, {x, 0, 1}, {y, 0, 1}, AspectRatio -> 0.1, ColorFunction -> colorfn]


By the way this question may be of tangential interest: