# How to plot a sequence of short lines of specified colours

Further to my impasse with ListVectorPlot questions 155785 and 156025, I am trying to restart from basics. I have tried but couldn't find the right instructions. Sorry to have to ask.

Can anyone please write code to plot a series of short lines from (x,k*sin[x]) to (x+.1*kx,ksin[x]+.1) for {x, -1.57, 1.57, .1} and {k, {.01, .2, .4, .6, 1}} with according colors {Red, Brown, Blue, Pink, Purple} Thank you very much.

Then I could use Show to combine this with a parametric plot of (x,k*sin[x]) with the the same colors for the same k to achieve what I wanted ListVectorPlot to do, but it always mixed up the colours or the scaling of the short lines (representing vectors representing a complex function).

## 1 Answer

color[k_] :=
Switch[k,
Evaluate[Sequence @@ (Flatten@
Transpose[{{0.01, 0.2, 0.4, 0.6, 1}, {Red, Brown, Blue, Pink,
Purple}}])]]

Graphics[Table[
{color[k], Line[{{x, k*Sin[x]}, {x + 0.1*k*x, k*Sin[x] + 0.1}}]},
{x, -1.57, 1.57, 0.1}, {k, {0.01, 0.2, 0.4, 0.6, 1}}]] Show[
ParametricPlot[
Evaluate@Table[{x, k*Sin[x]}, {k, {0.01, 0.2, 0.4, 0.6, 1}}],
{x, -1.57, 1.57},
PlotStyle -> {Red, Brown, Blue, Pink, Purple}],
Graphics[Table[
{color[k], Line[{{x, k*Sin[x]}, {x + 0.1*k*x, k*Sin[x] + 0.1}}]},
{x, -1.57, 1.57, 0.1}, {k, {0.01, 0.2, 0.4, 0.6, 1}}]]] • V. grateful for your two suggestions.The first worked beautifully on version 7 here but the second went awry, I couldn't change its strange graph which had dots instead of line segments for x>0 and nothing but the base curve for x<0. But it doesn't matter since the first way works here. – simon Oct 14 '17 at 2:35
• @simon - somehow in the cut and paste a comma got dropped. Try it now with the comma added back. – Bob Hanlon Oct 14 '17 at 2:53
• I found that in the end, I thought it was my computer's cut and paste error.I would have expected an error message from Mathematica. For the base graph I had Plot[Evaluate@Table[k*Sin[x],{k,{.01,.2,.4,.6,1}}],{x,-1.57,1.57},PlotStyle->{Red,Brown,Blue,Pink,Purple}] which is a teeny bit simpler – simon Oct 14 '17 at 3:20
• I never would have figured out that Switch on my own in a miilion years – simon Oct 14 '17 at 3:33