Jumping from one dimension (1D) to two dimensions (2D)

Here is a sample data file

m = {{-10,3,1},{-7.5,12,3},{-1.5,5,2},{2,4,4},{3,7,4},{6,9,5},{7,1,5},
{8,3,1},{9,12,2},{10,8,5}};

The first element of the list is a point on the x-axis, while the other two are integers for other information.

Now let's create a color code depending on the third integer element

getColor[m_List, i_Integer] := Module[{s = m[[i, 3]]},
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 let's plot the color points on the x-axis

data = Table[{PointSize[0.001], getColor[m, i], Point[{m[[i, 1]], 0}]},
{i, 1, Length[m]}];
S0 = Graphics[data] The above plot does not correspond to the sample data but to the actual data file. Nevertheless we see that the colors are hardly visible since all points lie on the x-axis.

I would like the following: Get some height. In particular, for every color point $x_0$ to create a vertical line at $x_0$ with the same color let's say from $y_{min} = -1$ up to $y_{max} = 1$.

Any suggestions?

Many thanks in advance!

• Try Line? p.s. Which -> Switch will shorten your code here. – Kuba Dec 11 '15 at 10:36
• @Kuba You mean data = Table[{Thickness[0.001], getColor[m, i], Line[{{m[[i, 1]], -1}, {m[[i, 1]], 1}}]}, {i, 1, Length[m]}]; right? How can Which could be substituted with Which? – Vaggelis_Z Dec 11 '15 at 10:43

m = {{-10, 3, 1}, {-7.5, 12, 3}, {-1.5, 5, 2}, {2, 4, 4}, {3, 7, 4}, {6, 9, 5}, {7, 1, 5}, {8, 3, 1}, {9, 12, 2}, {10, 8, 5}};

colors = {Black, Darker[Green], Red, Blue, Magenta, Orange, Cyan, Brown};

data = Table[{colors[[m[[i, 3]]]], Line[{{m[[i, 1]], -1}, {m[[i, 1]], 1}}]}, {i, 1, Length[m]}];
S0 = Graphics[data] Or more compactly (you don't need Table):

Graphics[{colors[[#[]]], Line[{{#[], -1}, {#[], 1}}]} & /@ m]

EDIT for Jason B:

The graphic was made with the following additional options:

Frame -> True, AspectRatio -> 1/2, PlotRangePadding -> None
• When I type in your code, I don't see a frame at all, same with OP's code - I just see a bunch of really small dots for his. Am I doing something wrong? – Jason B. Dec 11 '15 at 10:47
• @JasonB Nothing wrong at all! The plot I posted was created using more options like Frame etc. – Vaggelis_Z Dec 11 '15 at 10:49
• @JasonB Sorry I added the options after I'd copied the code. See my edit. – Quantum_Oli Dec 11 '15 at 10:50
• When I use your code the results do not match. What you define colors = {Black, Darker[Green], Red, Blue, Magenta, Orange, Cyan, Brown}; does black correspond to option 1 or 0? – Vaggelis_Z Dec 11 '15 at 10:55
• Ah my bad, yeah I had assumed your colour values went from 1, not 0. Just change colours[[#[]]] to colours[[#[]+1]] – Quantum_Oli Dec 11 '15 at 10:58