# Is it possible to use vectorized Plot Legend?

I upload data using the following code

data = Import["L" <> # <> ".dat"] &/@{"10", "102",
"103", "104"};


My function is

W[L_, r_] := 1 + 3 L + 2 L^2 - 6 r*L - 6 L (r*L) + 6 (r*L)^2;

Tu[L_, r_, d_, koff_, u_, W_] := ((u/d^2)* W[L, r]+6 u (L - 1)) + koff ((u/d^2) W[L, r]+6L*u)


I try to plot my function and would like to use the same trick for Plot Legend as I used for uploading data

LVals = {10, 10^2, 10^3, 10^4};
Show[LogLogPlot[
Evaluate@Table[Tu[n, 0.5, d, 10^3, 10^5, W], {n, LVals}], {d, 0.01,
10^7}, AxesLabel -> {"d", "T"},
PlotLabel -> "T vs d", PlotLegends ->
"L ="<> # &/@LVals, ListLogLogPlot[data],
PlotStyle -> {Red, Blue, Green, Black}]


But it gives the following message:

"Options expected (instead of !(((PlotLegends -> \"L = \" <> #1 &)\ ) /@ LVals)) beyond position 2 in LogLogPlot"

The following code works

Show[LogLogPlot[Evaluate@Table[Tu[n, 0.5, d, 10^3, 10^5, W], {n, LVals}],{d,0.01, 10^7},
AxesLabel -> {"d", "T"}, PlotLabel -> "T vs d", PlotLegends ->LVals], ListLogLogPlot[data],
PlotStyle -> {Red, Blue, Green, Black}]


and gets the legend as

10 100 1000 10000

But I want the legend as

L=10 L=100 L=1000 L=10000

How should I do this?

p.s. Why do I also obtain the message:

OptionValue::nodef: "Unknown option !(\"PlotStyle\") for Graphics."

• 1a) a -> b[#]& /@ c is (a -> b[#])& /@ c instead of a -> (b[#]& /@ c) – Brett Champion Nov 5 '15 at 20:00
• 1b) Plot holds its arguments, so the Map doesn't even evaluate (otherwise you'd get a list of PlotLegend -> ... and be wondering why you legend shows up wrong.) – Brett Champion Nov 5 '15 at 20:02
• 2) PlotStyle is only an option for Plot, but Graphics (which is what Show is working with) doesn't know anything about it. (Unlike PlotRange and PlotLabel, which are general graphics options.) – Brett Champion Nov 5 '15 at 20:04
• @BrettChampion , how should I specify then that I want the same color for the same L for data and plotting curve? – Maria Nov 5 '15 at 20:45
• Use the same setting for PlotStyle in both LogLogPlot and ListLogLogPlot. – Brett Champion Nov 5 '15 at 21:03

ListLogLogPlot[data] does not impact the issue here, so I omit it for convenience. Then,

Show[LogLogPlot[
Evaluate@Table[Tu[n, 0.5, d, 10^3, 10^5, W], {n, LVals}], {d, 0.01, 10^7},
AxesLabel -> {"d", "T"}, PlotLabel -> "T vs d",
PlotLegends -> {"L = " <> ToString[#] & /@ LVals},
PlotStyle -> {Red, Blue, Green, Black}]]


gives the desired plot. The changes are to move PlotStyle -> {Red, Blue, Green, Black} inside LogLogPlot, as recommended by Brett Champion, and to rewrite PlotLegends.

• but why does # work without ToString in the case of importing data and doesn't in the case of PlotLegends? – Maria Nov 5 '15 at 20:48
• @Maria When you used Import["L" <> # <> ".dat"] &/@{"10", "102", "103", "104"}, your list already was made up of strings, like "10". You could, of course, use a list of strings with PlotLegends, if you wish. However, you could not use that same list in your Table`. – bbgodfrey Nov 5 '15 at 21:01