I'm having an issue with a notebook I'm running. I'm generating a bunch of plots, but the legends aren't showing up correctly. I generate a bunch of plots every time I run the program so I wrote a Module to make all the plots with one line rather than type it out over and over. The Module works right except for the plot legends.
Plots[o_, f_] := Module[{style, legends, alegends, a, b, c, d, e},
style = If[n == 2, {Red, Blue}, {Red, Blue, Green}];
legends = If[n == 3, {"ve","vm","vt"},If[n == 2,
If[m == 2, {"ve","vm"}, {"ve","vt"}], If[n == 4, {"ve", "vm", "vt", "vs"}, "error"]]];
alegends = If[n == 3, {"vebar","vmbar","vtbar"},
If[n == 2, If[m == 2, {"vebar","vmbar"}, {"vebar","vtbar"}],
If[n == 4, {"vebar", "vmbar", "vtbar", "vsbar"}, "error"]]];
a = LogLinearPlot[NN, {x, o, f}, PlotStyle -> style, PlotRange -> {{0, f}, {0, 1}},
Frame -> True, FrameLabel -> {"Distance [km]", "Survival Probability"},
PlotLegends -> Placed[legends, {1, 0.5}], PlotLabel -> "Neutrinos Normal Hierarchy"];
b = LogLinearPlot[NA, {x, o, f}, PlotStyle -> style, PlotRange -> {{0, f}, {0, 1}},
Frame -> True, FrameLabel -> {"Distance [km]", "Survival Probability"},
PlotLegends -> Placed[alegends, {1, 0.5}], PlotLabel -> "Anti-Neutrinos Normal Hierarchy"];
c = LogLinearPlot[IN, {x, o, f}, PlotStyle -> style, PlotRange -> {{0, f}, {0, 1}},
Frame -> True, FrameLabel -> {"Distance [km]", "Survival Probability"},
PlotLegends -> Placed[legends, {1, 0.5}], PlotLabel -> "Neutrinos Inverted Hierarchy"];
d = LogLinearPlot[IA, {x, o, f}, PlotStyle -> style, PlotRange -> {{0, f}, {0, 1}},
Frame -> True, FrameLabel -> {"Distance [km]", "Survival Probability"},
PlotLegends -> Placed[alegends, {1, 0.5}], PlotLabel -> "Anti-Neutrinos Inverted Hierarchy"];
CellPrint@ExpressionCell[#, "Output"] & /@ {a, b, c, d, e};
]
This returns a plots that look like the following:
As you can see I get the plot, the styling, the frame, the labels, but the legend only has "ve" and it doesn't correspond to the correct color -- the key is blue with "ve" but the plot has "ve" red and "vt" blue.
Any help with this would be greatly appreciated.
EDIT: n and m are inputs. n determines the number of flavors of particles I'm considering (in the listed case n = 2) and m determines which two I'm working with (in this case m = 3 so I'm looking at the 1st and 3rd flavor).
EDIT 2: Thanks to the answer by Verbeia and playing around a little I have realized that the problem isn't in the Plot Legends exactly. It's in the primary argument. Since the functions I'm plotting are list of size n (a parameter set within the program) and are output from another function I pass them to the LogLinearPlot function as the name of the list. However I've found that if you do that the legends doesn't behave correctly.
Consider the following:
lst = {Sin[x],Cos[x]};
LogLinearPlot[{Sin[x],Cos[x]},{x,1,2$\pi$},PlotStyle->{Red,Blue},PlotLegends->Placed[{"Sin[x]","Cos[x]"},{1,0.5}]
LogLinearPlot[lst,{x,1,2$\pi$},PlotStyle->{Red,Blue},PlotLegends->Placed[{"Sin[x]","Cos[x]"},{1,0.5}]
This produces the following two images:
The problem in my case is that the list of functions NN are the outputs of other functions in the program and since my code is designed to handle a general case of n = {2,3,4} I can't just list out my functions.
Plots
, so that the reader can run your code. It is difficult to solve a problem without being able to reproduce it. Also, what is the value ofn
? $\endgroup$