4
$\begingroup$

How can I make a formatting-rich label and put in on a 2D plot? Example:

Output example

Please note superscripts, different colors and a need to avoid evaluating the expression.

$\endgroup$
1
  • 1
    $\begingroup$ x = 4; y = 5; Plot[Sin[x], {x, -Pi, Pi}, PlotLabel -> TraditionalForm[ Style[HoldForm[x^3], Blue, 32] + Style[HoldForm[y^3], Red, 32]]]? $\endgroup$
    – kglr
    Dec 15, 2017 at 10:22

3 Answers 3

7
$\begingroup$

HoldForm may help with keeping the symbols unevaluated.

A quick example may be something like this:

Plot[Sin[x] + Sin[2 x^6], {x, -2, 2}, 
PlotLabel -> 
Style[HoldForm[Sin[x]] 
+ Style[HoldForm[Sin[2 x^.2]], Bold, Red], 
Blue]]

enter image description here

$\endgroup$
7
$\begingroup$

Another option is to use MateX, and the math also looks better :)

Needs["MaTeX`"]
SetOptions[MaTeX,"Preamble"->{"\\usepackage{xcolor}"}]
label=MaTeX[
      "\\textcolor{blue}{\\sin(x)}+\\textcolor{red}{\\sin\\left( 2 x^{0.2} \\right)}",
      Magnification->2]

Now

  Plot[Sin[x]+Sin[2 x^6],{x,-2,2},PlotLabel->label]

Mathematica graphics

You can go a little fancy and box it

label=MaTeX[
"\\boxed{\\textcolor{blue}{\\sin(x)}+\\textcolor{red}{\\sin\\left( 2 x^{0.2} \\right)}}",
   Magnification->1.5]

Mathematica graphics

And little more fancy and color the box also

label=MaTeX[
"\\color{magenta}\\boxed{\\textcolor{blue}{\\sin(x)}+\\textcolor{red}{\\sin\\left( 2 x^{0.2} \\right)}}",
   Magnification->2]

Mathematica graphics

ps. I am not good in coloring, so may be there is better color for the frame.

$\endgroup$
1
  • $\begingroup$ Thank you, Nasser! MaTeX is really good for beautifying. And self-explanatory as well. $\endgroup$
    – einy
    Dec 16, 2017 at 11:36
3
$\begingroup$

Just type it as usual. Type "x", select the x, press Command - Shift - T to convert it to traditional form, then type and format as you normally would. See the Format menu and the usual shortcuts for typing math.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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