15
$\begingroup$

Superscripts can be included in axis labels by the use of the caret symbol (e.g., Plot[x^2, {x, -1, 1}, AxesLabel -> {x, x^2}]).

How does one include subscripts in an axis label? The use of the underscore character does not seem to work (e.g., Plot[f, {x, -1, 1}, AxesLabel -> {x, f_i(x)}]).

$\endgroup$

4 Answers 4

15
$\begingroup$

There is a subtle problem if you use strings as axis labels. Look closely at a plot like this:

Plot[f, {x, -1, 1}, AxesLabel -> {x, "\!\(\*SubscriptBox[\(f\), \(i\)]\)(x)"}]

You will see that the argument x in the function appears in a different font style than the argument on the horizontal axis.

To make sure that you get a consistent font style on both axes using the default styling for graphics, you should use the following:

Plot[f, {x, -1, 1}, AxesLabel -> {x, HoldForm[Subscript[f, i][x]]}]

Of course, to enter the Subscript expression in your label, you can still use the keyboard shortcuts that are mentioned by @Szabolcs.

The argument in HoldForm is your vertical label, typed in actual Mathematica syntax with square brackets for the function argument. I didn't surround the horizontal label in HoldForm, but you could do that for safety, in particular if your variable x has been assigned a value somewhere else in the Notebook.

$\endgroup$
2
  • $\begingroup$ Thanks, that ensures consistent typesetting of the axis labels. In my case, variables in the axis labels remain italicized. $\endgroup$
    – user001
    Mar 15, 2012 at 18:59
  • 1
    $\begingroup$ Yes, it's TraditionalForm. $\endgroup$
    – Jens
    Mar 15, 2012 at 19:01
6
$\begingroup$

Enclose the label in quotation marks for safety (just in case any symbols you use in them are defined), and enter two-dimensional input. Check the documentation on how to do it. You can enter a subscript using Ctrl-_ or Ctrl--. The Basic Math Assistant palette can be useful as well---it has a Typesetting section.

$\endgroup$
7
  • $\begingroup$ oooh, how do you do the nice CTRL commands? $\endgroup$
    – tkott
    Mar 15, 2012 at 18:44
  • $\begingroup$ @tkott Click the edit link to see ;-) It was really useful here because CTRL-- isn't very clear... Maybe CTRL-[-] $\endgroup$
    – Szabolcs
    Mar 15, 2012 at 18:44
  • $\begingroup$ smacks head thanks :) $\endgroup$
    – tkott
    Mar 15, 2012 at 18:45
  • $\begingroup$ Despite the fact than I ran out of votes hours ago I keep trying to vote. It's become a habit. $\endgroup$
    – Mr.Wizard
    Mar 15, 2012 at 18:46
  • $\begingroup$ Thanks. When I enclose the label in quotation marks, it romanizes the text. Can I force it to remain italic? If I try LabelStyle->{Italic}, the tick labels are italicized in addition to the axis labels. I prefer for the axis labels to be italic and the tick labels to be roman. $\endgroup$
    – user001
    Mar 15, 2012 at 18:55
3
$\begingroup$

That's because _ is only a subscript in LaTeX world. In MMA, you can simply use CTRL+-. The following should show you what I mean (once you copy it into MMA):

Plot[Sin[x], {x, -1, 1}, 
 AxesLabel -> {x, "\!\(\*SubscriptBox[\(f\), \(i\)]\)[x]"}]

Note that the reason that x^2 shows up like it does is because ^2 is automatically changed to MMA's boxes / display format. If you were to write:

Plot[Sin[x], {x, -1, 1}, AxesLabel -> {x, "x^2"}]

You'll notice the caret stick around.

$\endgroup$
1
  • $\begingroup$ Thanks, I erroneously tend to assume I can transplant LaTeX practices to Mathematica. $\endgroup$
    – user001
    Mar 15, 2012 at 18:53
1
$\begingroup$

Another option is to create the label with strings:

Plot[f, {x, -1, 1},
 AxesLabel -> {x, 
   Style[Row[{Subscript["f", "i"], "(x)"}], FontFamily -> "Times", 12,
     Italic]}]
$\endgroup$
2
  • $\begingroup$ This works fine in most simply labels, but it quickly gets ugly when you have actual Mathematica expressions as labels. Just replace the vertical label by Sin[x] and ask how you'd format that in a string so that it doesn't come out as sin(x) but sin(x). This is just a simple example - the point is that it's much better to let the default TraditionalForm in plot labels do the work for you. $\endgroup$
    – Jens
    Mar 15, 2012 at 21:02
  • $\begingroup$ I agree @Jens but the question related to a simple subscript. $\endgroup$ Mar 15, 2012 at 21:04

Your Answer

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

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