1
$\begingroup$

I have these four different functions in the same plane:

    Plot[Evaluate[Table[Sqrt[2/Pi] Sin[(n Pi x)/Pi], {n, 4}]], {x, 0, Pi},
    AxesLabel -> {"x", "\[CapitalPhi]"}, 
    PlotLegend -> {"n = 1", "n = 2", "n = 3", "n = 4"}, 
    PlotStyle -> {{Thick, Blue}, {Thick, Dashed, Red},
    {Thick, DotDashed, Orange}, {Thick, Dashing[Large], Green}}]

Now I want to plot those four functions, each one in a different plane, preserving their unique properties. I tried something like:

    Table[Plot[Sqrt[2/Pi] Sin[(n Pi x)/Pi], {x, 0, Pi}, 
    AxesLabel -> {"x", "\[CapitalPhi]"}], {n, 4}, 
    PlotLegend -> {"n = 1", "n = 2", "n = 3", "n = 4"}, 
    PlotStyle -> {{Thick, Blue}, {Thick, Dashed, Red},
    {Thick, DotDashed, Orange}, {Thick, Dashing[Large], Green}}]

but Mathematica tells me that it does not have the correct form of an iterator. How can I solve this?

$\endgroup$

2 Answers 2

1
$\begingroup$

Try this:

lst = {Blue, {Dashed, Red}, {Orange, DotDashed}, {Green, 
    Dashing[Large]}};
Grid[{Table[
   Plot[Sqrt[2/\[Pi]] Sin[(n \[Pi] x)/\[Pi]], {x, 0, \[Pi]}, 
    AxesLabel -> {"x", "\[CapitalPhi]"}, ImageSize -> 250, 
    PlotLabel -> Row[{"n=", n}], PlotStyle -> {Thick, lst[[n]]}], {n, 
    4}]}]

enter image description here

Have fun!

$\endgroup$
4
  • $\begingroup$ WOWWW!!! Thanks A LOT for this, bro! If you could explain me how does that "lst" work, you'll be my god from now. Please! $\endgroup$
    – Fermath
    Nov 17, 2021 at 0:12
  • $\begingroup$ I've already figured out. You are defining a set called lst. The set can be defined as we wish. :) $\endgroup$
    – Fermath
    Nov 17, 2021 at 11:57
  • $\begingroup$ I defined an auxiliary list: lst = {Blue, {Orange, DotDashed}, {Green, Dashing[Large]}};. Its first element is lst[[1]]. It is equal to Blue. The second element, lst[[2]] is {Dashed, Red} and so on. Therefore, PlotStyle -> {Thick, lst[[n]]} for each element of the Table gives the desired style option. $\endgroup$ Nov 17, 2021 at 13:38
  • $\begingroup$ Thank you. Have a great day! $\endgroup$
    – Fermath
    Nov 17, 2021 at 14:10
0
$\begingroup$

Try this:

Table[Plot[Sqrt[2/Pi] Sin[(n Pi x)/Pi], {x, 0, Pi}, 
AxesLabel -> {"x", "\[CapitalPhi]"}, 
PlotLegends -> {"n = 1", "n = 2", "n = 3", "n = 4"}, 
PlotStyle -> {{Thick, Blue}, {Thick, Dashed, Red}, {Thick, 
DotDashed, Orange}, {Thick, Dashing[Large], Green}}], {n, 4}]
$\endgroup$
1
  • 1
    $\begingroup$ I've Mathematica ver.8.0, so PlotLegends is not supported :( Thanks anyway, bro. $\endgroup$
    – Fermath
    Nov 16, 2021 at 23:59

Your Answer

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

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