# Labeling points on a graph with their coordinates in parentheses

I need to create some graphs in Mathematica with a bunch of labels, such as axes labels, graph labels, etc. In particular, there must be some points that must be labeled with their coordinates. Thanks to Internet search and this website in particular, I learned how to use the Epilog option. So I can do things like

Plot[x^2, {x, 0, 1}, Epilog -> {Text[y == x^2, {0.5, 0.5}]}]


to label an equation or

 ListPlot[{{1, 1}}, Epilog -> {Text["(1,1)", {0.5, 0.5}]}]


to label a point. Thru my experimenting, as you can see in these two examples, I figured that meaningful Mathematica inputs can be used in Text, but meaningless (for Mathematica) would cause an error message, so I do them as strings in quotes.

Now here's a problem. I need to label a point whose x-coordinate is 2/3, and I want it to look as a stacked fraction. I can't type coordinates of points in parentheses without quotes because for Mathematica it's an error. But if I type it in quotes, the parentheses don't stretch vertically, which doesn't look right. Can anybody advise a solution to this problems?

If you don't mind using boxes and DisplayForm then this will work for you:

ListPlot[{{1, 1}},
Epilog -> {Text[
DisplayForm@
RowBox[{"(", FractionBox["2", "3"], ",", "1", ")"}], {0.5,
0.5}]}] • No, I don't mind using anything, if it gets the job done! This output looks perfectly as what I want. Feb 9, 2014 at 17:36

Here are two possibilities. The first one has the advantage of allowing control of color, font properties, etc. The second one gives better element spacing.

ListPlot[{{2/3, 1}}, Epilog -> {Text[Style[{{2/3, ",", 1}}, "InlineFormula"], {0.5, 0.5}]}] ListPlot[{{2/3, 1}},
Epilog -> {Text[MatrixForm[{{2/3, ",", 1}}, TableSpacing -> {0., 0.3}], {0.5, 0.5}]}] • good solution but too much white inner spacing in there between the numbers. If these good be squashed closer they will look better. Feb 9, 2014 at 8:50
• @Nasser. painfully aware of that. Working on it, but so far no good results. Feb 9, 2014 at 8:52
• @m_goldberg: MatrixForm[#, TableSpacing -> {0, 0}]
– ciao
Feb 9, 2014 at 9:06
• @rasher. Thanks for the tip. Feb 9, 2014 at 9:25
• @m_goldberg: thank you very much for these suggestions! As a follow-up question, if I might: what exactly is InlineFormula? I couldn't find it in Mathematica documentation. Feb 9, 2014 at 17:12

If you can live with "{}" instead of "()", then a simple solution is to use TraditionalForm

ListPlot[{{2/3, 1}}, Epilog -> {Text[Style[TraditionalForm[{2/3, 1}],Red], {0.5, 0.5}]}] if you want "()" instead of "{}" then will try something else.

If you do not want paranthesis at all:

ListPlot[{{2/3, 1}}, Epilog -> {Text[Style[Row[{TraditionalForm[2/3], ",", 1}], Red],
{0.5, 0.5}]}] btw, there seems to be a bug in Mathematica, as it is not able to parse the following in TeXForm. The idea is to use TeXForm to typeset the labels. But Mathematica does not like the following:

ToExpression["\\left( \\frac{2}{3} , 1 \\right)", TeXForm, HoldForm] But the above is valid Latex code: The idea is to use Latex for typesetting things instead. (this way one can have a balanced () instead of using {} ). If TeXForm would have worked, then you could then do the following

ListPlot[{{2/3, 1}},
Epilog -> {Text[Style[ToExpression["\\left( \\frac{2}{3}, 1 \\right)",
TeXForm, HoldForm], Large], {0.5, 0.5}]}]


But this now does not work. But one coordinate works:

ListPlot[{{2/3, 1}}, Epilog -> {Text[Style[
ToExpression["\\left( \\frac{2}{3} \\right)", TeXForm, HoldForm], Large], {0.5, 0.5}]}] Also, it is really strange, since "\left(" and "\right)" do not even show up in the final output.

• I had tried TraditionalForm myself. But the problem is exactly that I have to have it in parentheses. I didn't know the trick with using TeX input, so thanks for this one! Too bad (and weird) it doesn't work in this case... Feb 9, 2014 at 17:34