1
$\begingroup$

To avoid issues, I post here the photo to explain you better what my problem is.

enter image description here

So what I would like to have, is a "correct" writings of the legend text for the Blue function. I would like it to be written as

$$x^2 - 2$$

not as

$$-2 + x^2$$

Is there a way to do it?

Thank you!

Version: Mathematica 9

$\endgroup$

closed as off-topic by Bob Hanlon, user9660, MarcoB, Öskå, dr.blochwave Jan 9 '16 at 23:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, Community, MarcoB, Öskå, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Simply use Strings instead to avoid all issues. $\endgroup$ – Sascha Jan 7 '16 at 14:40
  • 2
    $\begingroup$ By inserting your code into your question as part of an image you have created more issues than you solved. Please enter code as markdown text as instructed in site editor instructions and the site FAQ. $\endgroup$ – m_goldberg Jan 7 '16 at 14:43
  • $\begingroup$ I don't think to know what Strings is.. Could you explain better? :/ @Sascha $\endgroup$ – Henry Jan 7 '16 at 14:43
  • $\begingroup$ Use "x^2 - 2" instead of x^2 -2 $\endgroup$ – Sascha Jan 7 '16 at 14:44
  • 2
    $\begingroup$ You obviously have to type in your expression as you did before. I just didn't know how to format inside a comment. In the example you posted just wrap the equation part you want to print inside " " $\endgroup$ – Sascha Jan 7 '16 at 14:50
3
$\begingroup$

You can solve your problem by indicating you want "TraditionalForm" applied to your legend text. Here is a simplified example you can adapt to your needs.

Plot[x^2 - 2, {x, -5, 5},
  PlotStyle -> Red,
  PlotLegends -> 
    SwatchLegend[{Red}, {Style[x^2 - 2, "TraditionalForm", Bold, Red]}]]

plot

Update

In V9, you can use

Plot[x^2 - 2, {x, -5, 5},
  PlotStyle -> Red,
  PlotLegends -> 
    SwatchLegend[{Red}, {Style[TraditionalForm[x^2 - 2], Bold, Red]}]]
$\endgroup$
  • $\begingroup$ This is perfect. Thank you again M_Goldberg!! $\endgroup$ – Henry Jan 7 '16 at 14:56
  • $\begingroup$ Oh Wait... I just tried it and.. nothing! What appears in my legend is still $$-2 + x^2$$ :( $\endgroup$ – Henry Jan 7 '16 at 14:58
  • $\begingroup$ I think you have Mathematica 10. I have 9 instead.. $\endgroup$ – Henry Jan 7 '16 at 14:59
  • $\begingroup$ @KimPeekII Yes, I am using V10.3 Your question didn't mention you wanted a solution for V9. $\endgroup$ – m_goldberg Jan 7 '16 at 15:01
  • $\begingroup$ I?m sorry, sometimes I forget I have the Version 9 xD I'm used to it and I forget the other people may have the 10 one! >.< $\endgroup$ – Henry Jan 7 '16 at 15:02
1
$\begingroup$

Just for a different approach:

Plot[x^2 - 2, {x, -5, 5}, PlotStyle -> Red,
 PlotLegends -> SwatchLegend[{Red},
   {PolynomialForm[x^2 - 2, TraditionalOrder -> True]}]]

enter image description here

$\endgroup$

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