matplotlit.pyplot.xtick lablel alignment with subscripts

Hi All,

Trying to tune alignment of xtick labels.

I have the following for my lables

···

===
import matlplotlib.pyplot as plt

x_dat = [1,2,3,4]
x_label = ['$\mathrm{nn}$' , '${}^2\mathrm{H}$', '${}^4\mathrm{He}$', '${}^4_{\Lambda\Lambda}\mathrm{He}$']

plt.xticks(x_dat,x_label)

you can see I have both superscripts and subscripts (and sometimes none) on these labels.
Try as I might, I can not figure out how to get these to align how I want (I have tried all the options from verticalalignment=option in the plt.xticks() command.

If LaTeX were rendering such fonts (in a TeX document), it would align the bottom of the characters, and then place the super and sub scripts accordingly.

It seems that matplotlib is creating a bounding box around each label, and then aligning according to the top, bottom or center of the corresponding bounding boxes.

Is there a way to get the alignment to work according to my above description (the LaTeX way)?
If it involves fine tuning the position of each label - could someone demonstrate a simple example of how to set the positions individually?

I am using the mathtext (there are issues I have had trying to get latex to work with my current set up, which I am still working on, but aren't sorted out yet).

Thanks,

Andre

From: Andre' Walker-Loud [mailto:walksloud@…287…]
Sent: Thursday, June 21, 2012 22:19

Hi All,

Trying to tune alignment of xtick labels.

[...]

Try as I might, I can not figure out how to get these to
align how I want (I have tried all the options from
verticalalignment=option in the plt.xticks() command.

[...]

Does the following do what you want?

    plt.xticks(x_dat, x_label, va='baseline')
    plt.gca().xaxis.set_tick_params(pad=16)