-2
$\begingroup$

Here is a sample data file

data = {{-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.

A color code regarding the second integer of the list

valrange = {0, 43};
data[[All, 2]] = Rescale[data[[All, 2]], valrange];
colfunc[x_, cf_] := If[(x[[3]] == 0), White, ColorData[cf][1 - x[[2]]]];

S0 = Graphics[{{PointSize[0.005]}, Point[{#[[1]], 0}, VertexColors -> 
     colfunc[#, "DeepSeaColors"]] & /@data}]

enter image description here

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$.

I tried

S0 = Graphics[{{Thickness[0.001]}, Line[{{#[[1]], -1}, {#[[1]], 1}}, 
     VertexColors -> colfunc[#, "DeepSeaColors"]] & /@ data}]

but it does not work. All lines have black color.

Any suggestions?

Many thanks in advance!

$\endgroup$
  • $\begingroup$ Graphics[{Thick, Line[{{0, 0}, {2, 1}}, VertexColors -> Red]}] $\endgroup$ – Kuba Dec 11 '15 at 13:06
  • $\begingroup$ So provide at least two elements or don't use VertexColors but just put the color before line. p.s. when you have {Pointsize[_]} hidden inside a list, it won't affect anything. $\endgroup$ – Kuba Dec 11 '15 at 13:08
  • $\begingroup$ @Kuba I don't quite understand your suggestion. I want shades of blue not specific colors. $\endgroup$ – Vaggelis_Z Dec 11 '15 at 13:10
  • $\begingroup$ @Kuba Whan I evaluate Graphics[{Thick, Line[{{0, 0}, {2, 1}}, VertexColors -> Red]}] the line is black. $\endgroup$ – Vaggelis_Z Dec 11 '15 at 13:16
  • $\begingroup$ Yes, the point of that code was - you are doing the same thing... $\endgroup$ – Kuba Dec 11 '15 at 15:08
1
$\begingroup$
Graphics[{Thickness[0.01], 
   Line[{{#[[1]], -1}, {#[[1]], 1}}, 
      VertexColors -> colfunc[#, "DeepSeaColors"]] & /@ data}] /. 
        Rule[VertexColors, c_] :> VertexColors -> {c, c}

enter image description here

Or, shorter

Graphics[{Thickness[0.01], Line[{{#[[1]], -1}, {#[[1]], 1}},
   VertexColors -> {#, #} &[colfunc[#, "DeepSeaColors"]]] & /@ data}]
$\endgroup$
  • $\begingroup$ It works like a charm! A quick question: why S0 = Graphics[{Thickness[0.001], Line[{{#[[1]], -1}, {#[[1]], 1}}, VertexColors -> colfunc[#, "DeepSeaColors"]] & /@ data}] does not work and we need an extra rule? $\endgroup$ – Vaggelis_Z Dec 11 '15 at 13:29
  • $\begingroup$ By definition VertexColors needs two color directives. VertexColors -> {Red, Blue} would blend between Red and Blue. So, if we want only one color we have to write VertexColors -> {Red, Red} $\endgroup$ – eldo Dec 11 '15 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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