1
$\begingroup$

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

enter image description here

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?

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

Blend

enter image description here

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]

enter image description here

By the way this question may be of tangential interest:

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.