1
$\begingroup$

Let this code

f[x_]:=Piecewise[{{Sin[x],x>0},{Exp[x], x<=0}}];
Plot[f[x],{x,-5,5}, PlotLegends-> {"f(x)=" TraditionalForm[f[x]]}]

Then the part of the TraditionalForm in the legend appear braced, as it would be an array. How I can quit the braces? Morover: there is a way that the legend appear with more beautiful fonts (as it would be LaTeX)?

$\endgroup$
2
$\begingroup$
Plot[f[x], {x, -5, 5}, PlotLegends-> {Row[{"f(x) = ", TraditionalForm[f[x]]}]}]

enter image description here

Note: To see why you get TraditionalForm[f[x]] parenthesized check

 "f(x)=" TraditionalForm[f[x]] // FullForm

Times["f(x)=", TraditionalForm[Piecewise[List[List[Sin[x], Greater[x, 0]], List[Power[E, x], LessEqual[x, 0]]], 0]]]

that is, "f(x)=" is multiplied by TraditionalForm[f[x]].

$\endgroup$
  • $\begingroup$ one more question: when I evaluate just TraditionalForm[f[x]] the output is written using more beautiful fonts than when I did the same inside the legend of a plot. There is a way to put the same fonts in the legend? $\endgroup$ – Masacroso Jul 29 at 12:15
  • 1
    $\begingroup$ @Masacroso, If you know the font family you can use Style[TraditionalForm[f[x]], FontFamily -> fontfamily] to get the same style in the legend. For best labeling you might want to try Szabolcs's MaTeX package $\endgroup$ – kglr Jul 29 at 12:43

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.