# PlotLegend not showing

## Summary:

I plotted a few curves for the wavefunction of Quantum Harmonic oscillator problem with certain energy values. The plotlegends do not seem to work in the final output.

## Main Question or Discussion Point

Here, are the parts of the plot function

plot I:
p1 = Plot[Normal[g*Exp[-x^2/2] /. solute[] /. en -> 3], {x, -8, 8},
PlotStyle -> {Dashed, Gray}, PlotLegends -> Automatic];
(* Here, [B]g[/B]=1 - x^2 - x^4/6 - x^6/30 - x^8/168 - x^10/1080 , energy [B]en[/B] =3 and solute is the series solution of [B]g[/B] with unknown coefficients*)

plot II:
p2 = Plot[
Normal[g*Exp[-x^2/2] /. solute[] /. en -> 10], {x, -8, 8},
PlotStyle -> {Dashed, Red}, PlotLegends -> Automatic];

(* Here, g=1 - (9 x^2)/2 + (15 x^4)/8 - x^6/16 - (3 x^8)/896 - x^10/3840 *)
plot III:
p3 = Plot[
Normal[g*Exp[-x^2/2] /. solute[] /. en -> 17], {x, -8, 8},
PlotStyle -> {Thick, Black}, PlotLegends -> Automatic];

(* Here, g= 1 - 8 x^2 + 8 x^4 - (32 x^6)/15 + (16 x^8)/105 *)
and then the SHOW command as follows

Show command:
Show[{p1, p2, p3}, PlotRange -> All,
LabelStyle -> Directive[Blue, Italic, 12]]
What did I do wrong, here? Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
jedishrfu
Mentor
Try plotting one at a time and see if the plot legends appear then add one plot and try again.

If they appear on the first plot but not the 2nd or 3rd then you know where your error might be.

You could also try plotting them in reverse order.

The basic idea is to see if its the way you specified plot legends in each plot call vs a mistake in a plot that somehow hides the plot legend.

Also have you searched via google to see if others have had the same issue?

Here's what I found about plotlegends:

https://reference.wolfram.com/language/PlotLegends/ref/PlotLegend.html

In one example they do two plots in one call so maybe that's what you have to do.

Thanks @jedishrfu
I shall try your suggestion and see if it works and then post the working solution here.

So, this is the way i have learned to do it for the SHOW command
(I checked the plots individually and the PlotLegend worked fine. However, I found the following way to be more clean than filling the plot command with most of the attributes.)

Use of Legended:
Legended[Show[p1, p2, p3, PlotRange -> All],
Placed[LineLegend[{Gray, Red,
Green}, {"\!$$\*SubscriptBox[\(\[Psi]$$, $$2$$]\)(x)",
"\!$$\*SubscriptBox[\(\[Psi]$$, $$6$$]\)(x)",
"\!$$\*SubscriptBox[\(\[Psi]$$, $$8$$]\)(x)"}], {.9, .8}]]
The numbers in the curly brackets are the position coordinates {x,y} of the placement of the legend for the curve. The output is given below. Thanks a lot for the help! • jedishrfu
jedishrfu
Mentor
Thanks for your analysis, solution and insight. It’s always great to see that in a thread And will help future readers who stumble across it in their search for answers.

• Ishika_96_sparkles