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.

Consider this example plot.

Plot[
 1-Exp[-x],
 {x,0,3},
 AxesLabel->{"thickness (μm)","power density (W/m^2)"}
]

Example plot with quirky plot labels

Let us hold the typographical quality of the labels to the standard set by LaTeX. There are four distracting quirks:

  1. The "m" in "m^2" is italicized
  2. The "2" in "m^2" is set high enough to be above the "m"
  3. The parentheses in "(W/m^2)" are comically small
  4. The "µ" in "µm" is italicized

Am I entering the labels in the wrong form? How can they be fixed?

share|improve this question
2  
For the benefit of others reading this: the m^2 should be entered as Superscript[m, 2] (not literally, but using the shortcut — m, Ctrl-6, 2) for the italics to appear as shown in the image above. –  rm -rf Apr 3 '12 at 19:30
3  
Mma has \[Micro] for the 10^-6 prefix. It too is somewhat slanted. –  JxB Apr 3 '12 at 19:46
2  
You can switch off SingleLetterItalics like so: mathematica.stackexchange.com/a/5495/363 Then install the style sheet and set it as default: SetOptions[$FrontEnd, DefaultStyleDefinitions -> "newstyle.nb"] –  Chris Degnen Feb 15 '13 at 13:52

6 Answers 6

up vote 17 down vote accepted

To fix the superscript placement and the italic m, you can use the options ScriptBaselineShifts and SingleLetterItalics in Style. For example

Plot[1 - Exp[-x], {x, 0, 3}, AxesLabel -> {"thickness (μm)",
  Style[Row[{"power density ", Style["(",Larger], "W/m^2", Style[")", Larger]}],
    ScriptBaselineShifts -> {0, .5},
    SingleLetterItalics -> False, "TraditionalForm"]}]

Mathematica graphics

There are some other options in Style that might help. For example if you want a smaller font for the superscript, you can use the option ScriptSizeMultipliers.

share|improve this answer

For the µ you'd need an upright Greek font which I don't think Mathematica has (the comments point out that there's \[Micro] which looks a little better but isn't upright). For the other label, you can get slightly better typesetting by doing it the way I suggest in this answer.

So you'd simply take your plot as given in the question, highlight the part of the label that says (W/m^2), and then choose the menu item Cell > Convert to > TraditionalForm (or the keyboard shortcut).

The result will still have the parentheses too small, so you should delete them. Now you carefully move the cursor into the invisible box that surrounds the fraction and type the parentheses again. If you've typed them inside the TradionalForm box, the parentheses now appear big enough to match the fraction.

This is what you get:

Plot with labels looking a little better

Finally, we don't like the italics added automatically. But this is now easy to fix by highlighting each unwanted italic and pressing cmd-i:

Even better

Of course, if you don't want a stacked fraction in the vertical label, you can always go into that invisible box, right to the end, and start deleting backward until only the W is left in that TraditionalForm. Then re-type the fraction the way you like.

As you see with the italics, this way of entering typeset equations still leaves something to be desired. Another point that you may want to correct is the size of the superscript. To so that, add the following to your Plot command:

BaseStyle -> {ScriptMinSize -> 6}

This will allow the superscript to be made a little smaller. Alternatively, you can highlight whatever character you don't like and press cmd-- to reduce its size interactively. Likewise, you can move the superscript up or down, see the documentation for AdjustmentBox.

So below is the plot with all the formatting done as described above (superscript baseline adjusted two steps down with arrow keys ctrl-$\downarrow$). I also added a variable $I$ that still gets typeset italicized as it should be. It's also inside the TraditionalForm box.

With more formatting

I've included the input in the screen shot to show one important point: the typeset output was achieved while still maintaining a similarly readable typeset input, instead of having lots of styling command obscure the labels in the source code (all the typesetting happened interactively in the TaditionalForm box during input).

Afterthought

One may say that this interactive way of typesetting is not very "programming-like" (I don't write explicit source code on input). If you want to get a record of what you actually tweaked in those invisible boxes, you can always find that out by copying the whole input line (Plot[...] in its entirety) into a new cell and preceding it by InputForm@Hold@. Then you'll see the input in all its ugliness inside a Hold statement. Or highlight the input cell and use the menu Cell > Convert to > InputForm.

share|improve this answer
    
This is a good start. Can it be done without the stacked fraction? –  ArgentoSapiens Apr 3 '12 at 19:56
    
Absolutely. Just go into that invisible box, right to the end, and start deleting backward unti only the W is left in that TraditionalForm. Then re-type the fraction the way you like. I'll add one more thing about making the power smaller. –  Jens Apr 3 '12 at 20:02

Combining what Heike and Silvia have suggested gives:

Plot[1 - Exp[-x], {x, 0, 3}, AxesLabel -> {Row[{"thickness (", 
 Style["μ", FontFamily -> "Symbol"], "m)"}], Style[Row[{"power density ", Style["(", Larger], 
  "W/m^2", Style[")", Larger]}], ScriptBaselineShifts ->{0.5, 0.5}, SingleLetterItalics -> False]}]

enter image description here

The superscripted 2, the italic m and the italic µ are fixed.

share|improve this answer

Accidentally coming across this post, so here I just want to add some supplements about the slanted $\mu$.

There is indeed no Mathematica fonts containing upright $\mu$, but the system does offer method for invoking external fonts. For example using a Windows built-in font Symbol:

ToString[Style[Row[{
    Style["m", FontFamily -> "Symbol"],
    Style["m", FontFamily -> "Times"]
    }], 30], StandardForm]

upright μm

share|improve this answer

I've been struggling with this too. I ended up doing like what rm -rf suggested, but with a slightly different approach. I'm on a Mac.

  1. Use LaTeXiT to create a label with specific font size.
  2. Export it as a PDF with outlined fonts.
  3. Import it to Mathematica and use it as a label.

If the export format is just 'PDF vector format', Greek symbols can disappear when imported to Mathematica.

The disadvantages of this method are that

  1. We need to import PDF files, ie additional hassle.
  2. Their sizes are relatively large because of the outlining of fonts.
  3. The font of the labels may not match that of the tick numbers (unless, of course, we undertake more matching effort).
  4. We need to re-create a label that needs change.

I find them acceptable though, considering that

  1. The additional workflow is simple. It's less likely to cause us inconvenience when having to do it many times, compared to, with all due respect, the approaches of Heike and rm -rf above. (Anyway, this is subjective.)
  2. The Plot code is free of hacks.

Here is an example.

share|improve this answer

Mathematica is not a typesetting engine. If you want proper typography, you should use something that is good at it. Of course, you can wrestle with Mathematica with boxes and stuff to hack it for some cases, but you'll soon find that it breaks the minute you change something or try something more complicated. Jens' and Heike's answers show you how to approach the problem in Mathematica. However, if the end goal is to use it in a $\LaTeX$ document, I would highly recommend using EPS figures and psfrags (in latex) to typeset the labels the way you'd like.

Here's an example for your case:

Export["plot.eps", Plot[1 - Exp[-x], {x, 0, 3}, AxesLabel -> {"xlabel", "ylabel"}]];

Now, in latex, do something like:

\documentclass{article}
\usepackage{graphicx, psfrag}
\begin{document}
\begin{figure}
    \psfrag{xlabel}{thickness $\mu m$}
    \psfrag{ylabel}{power density $W/m^2$}
    \includegraphics{plot.eps}
\end{figure}
\end{document}

which produces the following output:

enter image description here

share|improve this answer
2  
This one looks the best (except the italics, which are easy to fix), but I like retaining the ability to share plots without first running them through LaTeX, particularly the LaTeX -> dvips -> ps2pdf workflow that pstricks requires. I agree with your first assertion, but don't tell that to Wolfram. See the sensational first sentence here: reference.wolfram.com/mathematica/guide/… –  ArgentoSapiens Apr 3 '12 at 20:56
    
Ok, I have a fix for that. I'll do it when I finish work for the day and ping you about it. –  rm -rf Apr 3 '12 at 21:15
    
I too agree with R.M when the question is phrased as a comparison to LaTeX output. What Heike and I are trying to do (if I may speak for Heike) is to show that Mathematica does have a self-contained set of typesetting tools so that we don't have to make LaTeX a requirement for acceptable-looking graphics labels anymore (as indeed it used to be). –  Jens Apr 3 '12 at 23:30
    
I guess it's better to use rm suggestion for standard use. –  Herman May 10 '13 at 9:11

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.