Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
u = Sin[x];  
v = Cos[x];
w = Cos[x]^2;
y = Sin[x]^3;

Needs["PlotLegends`"]

Plot[{u, v, w, y}, {x, -10, 10}, PlotRange -> All, 
 PlotStyle -> {AbsoluteDashing[{}], Dashed, DotDashed, Dotted}, 
 PlotLegend[{{Graphics[{AbsoluteDashing[{}], 
      Line[{{7, 0.1}, {8, 0.1}}]}], 
    "a=0.02"}, {Graphics[{Dashed, Line[{{7, 0.3}, {8, 0.3}}]}], 
    "b=0.03"}, {Graphics[{DotDashed, Line[{{7, 0.5}, {8, 0.5}}]}], 
    "c=0.04"}, {Graphics[{Dotted, Line[{{7, 0.7}, {8, 0.7}}]}], 
    "d=0.07"}}]]

the error is:

An option must be a rule or a list of rules....

Coordinate Skeleton[2] should be a pair of numbers, or a Scaled or Offset form

Would You please help me!

share|improve this question
3  
PlotLegends is a package we all love to hate. Check this question and all the other questions cited there. –  Sjoerd C. de Vries Jun 11 '12 at 21:18
1  
I need to call my WRI rep today and I think I will (once again) complain to him about Mathematica's pathetic legends capability. –  David Skulsky Jun 12 '12 at 13:09
    
@SjoerdC.deVries: Thanks alot. –  Sara Jun 12 '12 at 14:16
    
@DavidSkulsky Not that I expect an answer from a WRI rep, but: I'm particularly curious why WRI added all those flashy financial plotting functions (TradingChart etc. which I often think are quite frivolous) before fixing their basic but crucial plot label and tick mark functionality for the core plotting functions. –  Jens Jun 12 '12 at 14:47
    
@DavidSkulsky In particular: why do I have to load a package with Needs to make a normal legend for Plot, while something like TradingChart is in the System context even though it's an obvious niche function? –  Jens Jun 12 '12 at 14:53
show 2 more comments

1 Answer 1

The message "An option must be a rule or a list of rules..." tells you that PlotLegend should be a rule, not a function call. In other words, you should write something like

Plot[{u, v, w, y}, {x, -10, 10}, PlotRange -> All, PlotStyle -> {AbsoluteDashing[{}],
Dashed, DotDashed, Dotted}, PlotLegend->{{Graphics[{AbsoluteDashing[{}], 
Line[{{7, 0.1}, {8, 0.1}}]}], "a=0.02"}, {Graphics[{Dashed, Line[{{7, 0.3}, {8, 0.3}}]}],
"b=0.03"}, {Graphics[{DotDashed, Line[{{7, 0.5}, {8, 0.5}}]}], 
"c=0.04"}, {Graphics[{Dotted, Line[{{7, 0.7}, {8, 0.7}}]}], "d=0.07"}}]

This doesn't exactly work, but I don't know exactly what you're trying to accomplish with the legend. See if this works for you:

Plot[{u, v, w, y}, {x, -10, 10}, PlotRange -> All,
PlotStyle -> {AbsoluteDashing[{}], Dashed, DotDashed, Dotted},
PlotLegend -> {"a=0.02", "b=0.03", "c=0.04", "d=0.07"}]

You could also use the autoLegend function described in the question referenced by Sjord above. Here's an example (you'll need to load the functions described in the question prior to running this example):

g = Plot[{u, v, w, y}, {x, -10, 10}, PlotRange -> All, 
PlotStyle -> {AbsoluteDashing[{}], Dashed, DotDashed, Dotted}]

autoLegend[g, {"a=0.02", "b=0.03", "c=0.04", "d=0.07"}, 
Background -> Directive[LightOrange, Opacity[1]], 
Alignment -> {Right, Top}]

enter image description here

share|improve this answer
    
I formatted your code into a more legible form, but we collided in our revisions. –  belisarius Jun 11 '12 at 20:40
    
Okay, I'll try to clean it up. Thanks! –  David Skulsky Jun 11 '12 at 20:40
    
@David Skulsky Considering your suggestion most of my problems solved, Thank you so much, Just one thing, is there any way to increase the length of the lines in PlotLegend? I mean, I don’t want to have a big PlotLegend, so by using LegendSize→{0.3,0.3} I tried to have a small one, but in this way the length of the lines are too small and it is not clear which line is Dash and which one is Dot, for example. –  Sara Jun 12 '12 at 6:53
1  
@Sara: As Sjord alluded to above, the PlotLegends package leaves much to be desired and I never use it, but I did quickly scan the documentation and I don't think there's an option to do what you want. You could probably accomplish your goal by tinkering with the graphics primitives, but that seems like a ridiculous amount of work. Instead, I'd suggest trying the autoLegend function provided in the question Sjord references above. I'll add an example to my answer. –  David Skulsky Jun 12 '12 at 12:56
    
@DavidSkulsky:It is great, thank you so much for your time and consideration, I will definitely use it. Infact I accomplished what I want by using Epilog and Inset, but as you said It is a ridiculous way. –  Sara Jun 12 '12 at 14:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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