# Easiest way to create a formatting-rich plot label?

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

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

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

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]]


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]


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]


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]


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

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

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.