Using a function name instead of its definition in AxesLabel

What you are looking for can be achieved by wrapping the labels in HoldForm, or if you prefer, HoldForm@InputForm. For example, here is a plot that combines both labeling issues you mentioned:

f = x^2;
Plot[f, {x, -2, 2}, AxesLabel -> {x, HoldForm[InputForm[E = f]]}]

The two issues you mention are indeed separate:

  1. To get f instead of $x^2$ you should use HoldForm, but that still allows the display of TraditionalForm shorthand forms for built-in symbols such as E (which is Euler's constant but is pretty-printed as $\mathbb e$).
  2. To prevent the replacement of E by $\mathbb e$, InputForm can be used.

As you noticed, using strings in labels (though sometimes perfectly fine) has undesirable effects on the font and requires more "finger-painting" with styles. The HoldForm approach is easier to use and the code is easier to read when labels get complicated.

See also this related question.

To expand on this topic:

Sometimes you need more complicated labels that require "two-dimensional" typesetting, as in $\psi = \frac{1}{2}\int f(x) \mathbb{d}x$, see this image:

formulas in labels

Edit: how to get formatting into labels in general

For output like the above, the essential ingredient is that the expression should be wrapped in a FormBox. Strings aren't made for two-dimensional display, but Mathematica has a way of sneaking FormBoxes into strings: see the documentation.

Therefore, you can get a two-dimensional formula into a plot label either using HoldForm or a string. Using HoldForm, I got the formatting in the image by doing the following:

  1. Create the formula in a TraditionalForm environment. This could e.g. be in a Text cell by starting an equation with Ctrl-( and ending with Ctrl-).
  2. Copy this formula from within that math inset.
  3. Lay out your plot by typing something like Plot[f, {x, -2, 2}, AxesLabel -> {x, HoldForm[ ]}]
  4. In the blank space that I have left inside the HoldForm[ ], paste the copied equation.
  5. You will be asked if you want to wrap the TraditionalForm expression in a FormBox, and the answer is yes.
  6. Provided that the pasted expression obeys Mathematica syntax, you should now be able to evaluate the plot cell and get the output shown above.

Now in some cases you want to label a graph with a two-dimensional formula that doesn't obey Mathematica syntax, and in that case you would replace step 4. above by this:

Plot[f, {x, -2, 2}, AxesLabel -> {x,""}

Instead of HoldForm, I now left an empty string "" in the label. Now proceed as above with step 4, for example using an equation like

-(\[HBar]^2/(2m))\[PartialD]^2 \[Psi]

entered in a math inset (in a text cell as in step 1). If you tried this with HoldForm, it would give a syntax error because the \[PartialD] is being used in a mathematically acceptable but syntactically incorrect way.

Edit 2: the fastest way

The way I described copying and pasting of TraditionalForm into strings was based on my habits, but it's actually not the fastest. I should adjust my habits to the following: In the code for your plot, type a single string placeholder letter for your label, such as "y". Using the mouse, highlight the y in your string and go to the menu item Cell > Convert To > TraditionalForm (or use the keyboard shortcut). This creates the all-important FormBox. Since this box is invisible, you now have to use the arrow keys or mouse to get inside this FormBox, right next to to the placeholder y. From here, you can start typing any arbitrary formula which will then be typeset as TraditionalForm in the plot label.

So in conclusion, HoldForm is a very direct way of getting valid Mathematica expressions into labels without expanding them, and strings should be used in combination with the FormBox wrapper method above to typeset arbitrarily complicated labels.


You can use strings for the labels and Style them as you like — change colour/font/fontsize, etc. For example:

Plot[Sinc[x], {x, 0, 10}, PlotStyle -> Darker@Green, 
  AxesLabel -> (Style[#, Italic, Red, FontFamily -> "Verdana"] & /@ {"x","sinc(x)"})]

This will style only the labels and leave the tick marks intact.

enter image description here