# 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?

## closed as off-topic by J. M. will be back soon♦Apr 5 '17 at 4:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – J. M. will be back soon
If this question can be reworded to fit the rules in the help center, please edit the question.

• 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: