1
$\begingroup$

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."

$\endgroup$
5
  • $\begingroup$ 1a) a -> b[#]& /@ c is (a -> b[#])& /@ c instead of a -> (b[#]& /@ c) $\endgroup$ Nov 5, 2015 at 20:00
  • $\begingroup$ 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.) $\endgroup$ Nov 5, 2015 at 20:02
  • $\begingroup$ 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.) $\endgroup$ Nov 5, 2015 at 20:04
  • $\begingroup$ @BrettChampion , how should I specify then that I want the same color for the same L for data and plotting curve? $\endgroup$
    – Mary
    Nov 5, 2015 at 20:45
  • $\begingroup$ Use the same setting for PlotStyle in both LogLogPlot and ListLogLogPlot. $\endgroup$ Nov 5, 2015 at 21:03

1 Answer 1

2
$\begingroup$

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.

enter image description here

$\endgroup$
2
  • $\begingroup$ but why does # work without ToString in the case of importing data and doesn't in the case of PlotLegends? $\endgroup$
    – Mary
    Nov 5, 2015 at 20:48
  • 1
    $\begingroup$ @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`. $\endgroup$
    – bbgodfrey
    Nov 5, 2015 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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