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'm trying to label a 2D plot with something like $A/B$ rather than $\frac{A}{B}$. I have tried:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {HoldForm[A/B], y}]

However, this leaves the $x$-axis as $\frac{A}{B}$. Any ideas?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Use InputForm:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {InputForm[A/B], y}]

Or just string:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {"A/B", y}]

You can also wrap these things in Style to get further:

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {Style["A/B", 18, Bold, FontFamily -> "Georgia"], y}] 
share|improve this answer
    
String works perfectly. I actually needed something in the form of $A/B_C$, which didn't render correctly with InputForm. Thanks. –  cosmoguy Nov 26 '12 at 3:00
add comment

If you would like to get a display along the lines of the $\LaTeX$ command \nicefrac (with a shifted baseline for the numerator and denominator), you could do the following:

niceFrac[x_, y_] := 
 DisplayForm[
  RowBox[{AdjustmentBox[HoldForm[x], BoxBaselineShift -> -.5], "/", 
    AdjustmentBox[HoldForm[y], BoxBaselineShift -> .5]}]]
SetAttributes[niceFrac, HoldAll]

Plot[Sin[x], {x, 0, 10}, AxesLabel -> {niceFrac[A, B], y}]

nicefrac

What I did in the function niceFrac is to give the first argument a nudge upward, and the second argument an equal downward push relative to the / symbol. This may be a useful compromise when you don't want to be completely one-dimensional but also don't want to waste too much space with the stacked fraction.

I added the HoldAll attribute only to allow you to typeset more complicated expressions that you don't want to evaluate (could be left out).

share|improve this answer
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.