# Creating a custom color plot with tones of colors

Here is a sample set of data

m = {{3.37778, -2.73333, 21, 2}, {0.644444, 2.28889, 9, 3},
{2.82222, -4.6, 13, 4}, {4.15556, -2.4, 17, 1},
{-0.866667, -0.4, 6, 2}, {3.64444, 2.26667, 26, 4},
{2.08889, 3.73333, 12, 3}, {1.73333, -4.48889, 12, 4},
{-4.44444, -0.777778, 14, 2}, {-4.62222, 2.2, 12, 5},
{0.977778, 0.755556, 18, 5}, {1.77778, -0.822222, 10, 1},
{-1.02222, -1.86667, 11, 2}, {4.62222, 4.82222, 16, 3},
{2., 2., 13, 3}, {0.666667, -1.88889, 8, 4},
{-2.15556, 4.64444, 18, 5}, {-3.08889, 3.37778, 12, 5},
{0.311111, -4.22222, 12, 4}, {-4.26667, -3.31111, 12, 2}};


The first two elements of the list represent the coordinates $(x,y)$, while the other two integers $k$, $n$, indicate other type of information.

Now let's setup a color code according to the second integer $n$ (last column)

getColor[m_List, i_Integer] := Module[{s = m[[i, 4]]},
Which[s == 0, Black, s == 1, Darker[Green], s == 2, Red, s == 3,
Blue, s == 4, Magenta, s == 5, Orange, s == 6, Cyan, s == 7,
Brown]];


and then create the graph

data = Table[{PointSize[0.02], getColor[m, i], Point[{m[[i, 1]],
m[[i, 2]]}]}, {i, 1, Length[m]}];
S0 = Graphics[data];


Now I would like the to keep the colors according to $n$ but modify their tone according to the value of the first integer $k$ (third column). In particular, plot again the $(x,y)$ points in tones of green, red, blue, magenta, etc where darker color means higher value of $k$.

EDIT

Applying @J.M method to the actual data file the output is the follwoing

clist = {Black, Darker[Green], Red, Blue, Magenta, Orange,
Cyan, Brown};
Point[Take[#, 2]]} &, {m, 1 - Rescale[m[[All, 3]]]}]}]


As we can see the entire plot is too dark and the colors are hardly distinguishable.

In case anyone wants to play with the actual data file

The resulted plot should be something like this

Any suggestions?

• Is $k$ bounded or unbounded? Dec 12, 2015 at 9:48
• Perhaps you can use the function Lighter with a k properly rescaled.
– user31159
Dec 12, 2015 at 9:50
• @J.M. Good question. $k$ is an integer. The code should read the data file and determine the minimum and maximum value of $k$ for every $n$. Dec 12, 2015 at 9:50
• @Xavier, yes, that's why I was asking about bounds on $k$. Would it be useful if, say $100$ and $500$ both gave colors that are visually the same? Dec 12, 2015 at 9:53
• @J.M. $k$ lies in the interval $[0,k_{max})$, where $k_{max}$ should be determined by reading the data file. The lower value of $k$ is always and for all $n$ equal to zero. Dec 12, 2015 at 9:56

    colors = Lighter[#, 0.2] & /@ {Black, Darker[Green], Red, Blue, Magenta, Orange, Cyan, Brown};

cols = (Darker[colors[[#[[4]] + 1]], #[[3]]/40.] & /@ bigM);

cols = Partition[cols, 451];

Image[cols, ColorSpace -> "RGB"]


EDIT (diagnostics):

• bigM used but not set! Dec 12, 2015 at 11:34
• It's the data from your file... Dec 12, 2015 at 11:37
• When I evaluate Image[] I get the following error: Image::imgarray: "The specified argument {<<1>>} should be an array of rank 2 or 3 with machine-sized numbers." Dec 12, 2015 at 11:42
• Sounds like cols should be an array of rank 2 or 3! Which it should, and is in my case. I guess you haven't got your data in the same format as me, or you for that case. Make sure you import your data file such that it ends up in the same format as your example data - ie a 1d list of length 4 lists. Dec 12, 2015 at 11:46
• @Vaggelis_Z, it is rather rude to withhold your Accept subject to the poster making cosmetic tweaks which aren't even related to the question. Please try to judge answers based on how well they address the question you actually asked, not how well they meet your unstated final requirements. This is not a bespoke coding service! By all means ask a new question about framing images, however. Dec 12, 2015 at 13:19