Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

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

share|improve this answer
    
No, I don't mind using anything, if it gets the job done! This output looks perfectly as what I want. –  zipirovich Feb 9 at 17:36
add comment

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

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

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.

share|improve this answer
    
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... –  zipirovich Feb 9 at 17:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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