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 1

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

  {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}}]]

enter image description here

With 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}],
   {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}}]]]

enter image description here

  • $\begingroup$ 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. $\endgroup$
    – simon
    Commented Oct 14, 2017 at 2:35
  • $\begingroup$ @simon - somehow in the cut and paste a comma got dropped. Try it now with the comma added back. $\endgroup$
    – Bob Hanlon
    Commented Oct 14, 2017 at 2:53
  • $\begingroup$ 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 $\endgroup$
    – simon
    Commented Oct 14, 2017 at 3:20
  • $\begingroup$ I never would have figured out that Switch on my own in a miilion years $\endgroup$
    – simon
    Commented Oct 14, 2017 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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