3
$\begingroup$

My aim is to plot each function with distinct style superimpose with color based upon parameter.

For instance, I have 3 functions of 1 variable and 1 parameter. Table command is used for iterating over parameter space & also for colouring the associated curve obtained from the Plot command. All 3 functions are plotted with 3 distinct plot style.

After scanning all...or may be I missed something in the search, but I'm not able to correct the PlotLegends misfit style both in Plot & ListPlot commands.

{k1, k2, dk} = {0.01, 0.09, 0.01};

f1[x_] = Sin[k x];
f2[x_] = Cos[k x];
f3[x_] = Sin[k x]*Cos[k x];

Plot[Evaluate[
  Table[Style[{f1[x], f2[x], f3[x]}, 
    ColorData["Rainbow"][(k - k1)/(k2 - k1)]], {k, k1, k2, 
    dk}]], {x, -5 Pi, 5 Pi},
 PlotStyle -> {"", Dashing[0.03, 0.01], Dashing[0.004]},
 PlotLegends -> {Placed[{"Amp1", "Amp2", "Amp3"}, {Right, Bottom}]}]

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

Improper syntax on dashing. Use this:

PlotStyle -> {"", Dashing[{0.03, 0.01}], Dashing[0.004]}

or better, to my taste

PlotStyle -> {Automatic, Dashing[{0.03, 0.01}], Dashing[0.004]}

e.g.

Plot[Evaluate[Table[Style[{f1[x], f2[x], f3[x]},
    ColorData["Rainbow"][(k - k1)/(k2 - k1)]],
   {k, k1, k2, dk}]], {x, -5 Pi, 5 Pi},
 PlotStyle -> {Automatic, Dashing[{0.03, 0.01}],
   Dashing[0.004]}, PlotLegends ->
  {Placed[{"Amp1", "Amp2", "Amp3"}, {Right, Bottom}]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ I'm amending my default settings also to get the corrections you just suggested...but thanks for the relook. $\endgroup$ Commented Oct 15, 2023 at 9:08

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.