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.

For some odd reason the PlotLegends output is not as expected.

Clear[f, g, v]
v = Function[x, k*x^-k];
g = Function[x, (x^-k)*Sin[x^k]/(1 + x^k)];
f = Function[x, x^k/(1 + x^k)];
With[{f = f, g = g}, 
Manipulate[Plot[{v[x], f[x], g[x], D[f[x] - g[x]]}, {x, 0, 5},
PlotLegends -> "Expressions"], {k, 1, 10}]]

enter image description here

share|improve this question
3  
What specifically is wrong with the output? –  whuber May 20 '13 at 19:38
    
I have to clarify that there is nothing wrong with the geometry of the function. The problem is the legend. The expression is rendered all wrong, –  Jose E Calderon May 21 '13 at 4:17
1  
@JoseECalderon: There is an answer that most probably solves your problem already, but I think your question would be much better if you state what it is that you expect (or more precisely want) to get from that input. I understand that the output is not what you want, but it seems to be what can be expected with some knowledge about the evaluation order and scoping quirks of Mathematica (where the latter is IMHO not exactly its strongest part)... –  Albert Retey May 21 '13 at 10:10

1 Answer 1

The expression that is plotted in the legend are the provided pure functions (with some scoped internal variable names). PlotLegends is somewhat confused so we have to provide explicit entries for the Legend. Since the desired result is somewhat unclear here a few suggestions:

v[x_, k_] := k*x^-k;
g[x_, k_] := (x^-k)*Sin[x^k]/(1 + x^k);
f[x_, k_] := x^k/(1 + x^k);
Manipulate[Plot[{v[x, k], f[x, k], g[x, k], D[f[x, k] - g[x, k]]}, {x, 0, 5},
                PlotLegends -> "Expressions"], {k, 1, 10}]

enter image description here

or, with the explicit expressions:

Manipulate[Plot[{v[x, k], f[x, k], g[x, k], D[f[x, k] - g[x, k]]}, {x, 0, 5},
            PlotLegends -> TraditionalForm /@ {v[x, k], f[x, k], g[x, k], 
                           D[f[x, k] - g[x, k]]}],
           {k, 1, 10}]

enter image description here

share|improve this answer

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.