I have a function of two variables which returns a vector of three components. For example


Now I want to do a 3D parametric plot for this function with the parameter being t for different values of the variable l(say 10 values).

I do the following

ParametricPlot3D[Evaluate[Table[func[l, t][[1]], {l, 1,10}]], {t, 0, 20}]

This works fine and I get 10 different lines with 10 different colors.

What I want is that the color of the lines should be mappable to a colorscale so that color of the line corresponds to the value of the parameter l on the colorscale. I also want the color scale to appear next to the plot.

How to do this? Thanks


1 Answer 1


Okay, so take some form for your function

func[l_, t_] := {
  x = 3 t Sin[l t];
   y = 3 t Cos[l t];
   z = l t + l; 
  {x, y, z}}

Then one way to get what you are looking for is like this,

   func[l, t][[1]], {t, 0, 5}, PlotStyle -> Hue[l/10], 
   PlotLegends -> {"l = " <> IntegerString[l]}],
  {l, 1, 10}],
 PlotRange -> All]

enter image description here

Here the color of the line is a function of l (specifically, it is Hue[l/10]). If you want a color bar instead, use

BarLegend[{Hue, {0, 10}}, ColorFunctionScaling -> True]

enter image description here


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.