7
$\begingroup$

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.

my ListPlot samples

Can anybody advise a solution to this problems?

$\endgroup$

3 Answers 3

6
$\begingroup$

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

enter image description here

$\endgroup$
1
  • $\begingroup$ No, I don't mind using anything, if it gets the job done! This output looks perfectly as what I want. $\endgroup$
    – zipirovich
    Feb 9, 2014 at 17:36
6
$\begingroup$

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

plot1

ListPlot[{{2/3, 1}}, 
  Epilog -> {Text[MatrixForm[{{2/3, ",", 1}}, TableSpacing -> {0., 0.3}], {0.5, 0.5}]}]

plot2

$\endgroup$
5
  • $\begingroup$ good solution but too much white inner spacing in there between the numbers. If these good be squashed closer they will look better. $\endgroup$
    – Nasser
    Feb 9, 2014 at 8:50
  • $\begingroup$ @Nasser. painfully aware of that. Working on it, but so far no good results. $\endgroup$
    – m_goldberg
    Feb 9, 2014 at 8:52
  • 1
    $\begingroup$ @m_goldberg: MatrixForm[#, TableSpacing -> {0, 0}] $\endgroup$
    – ciao
    Feb 9, 2014 at 9:06
  • $\begingroup$ @rasher. Thanks for the tip. $\endgroup$
    – m_goldberg
    Feb 9, 2014 at 9:25
  • $\begingroup$ @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. $\endgroup$
    – zipirovich
    Feb 9, 2014 at 17:12
3
$\begingroup$

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

Mathematica graphics

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

Mathematica graphics

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]

Mathematica graphics

But the above is valid Latex code:

Mathematica graphics

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

Mathematica graphics

Also, it is really strange, since "\left(" and "\right)" do not even show up in the final output.

$\endgroup$
1
  • $\begingroup$ 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... $\endgroup$
    – zipirovich
    Feb 9, 2014 at 17:34

Your Answer

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

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