Centering Tick Labels BETWEEN Tick Marks

"Alexander Michael" <[EMAIL PROTECTED]> writes:

> I would like to create a plot axis with major tick labels centered

> *between* major tick markers instead below tick markers.

Take a look at

[http://thread.gmane.org/gmane.comp.python.matplotlib.general/5271
](http://thread.gmane.org/gmane.comp.python.matplotlib.general/5271)
[http://thread.gmane.org/gmane.comp.python.matplotlib.general/5296](http://thread.gmane.org/gmane.comp.python.matplotlib.general/5296)
[
http://www.scipy.org/Cookbook/Matplotlib/Transformations](http://www.scipy.org/Cookbook/Matplotlib/Transformations)

--
Jouni

From your references, I have been mostly able to figure out how to do it. Thank you.
So far, I have:

create transformation with x in data coords and y in axes coordinates

transLabels = matplotlib.transforms.blend_xy_sep_transform(
ax.transData, ax.transAxes)

get major locator and usurp major formatter for custom positioning

major_locator = ax.xaxis.get_major_locator()

major_formatter = ax.xaxis.get_major_formatter()
ax.xaxis.set_major_formatter(matplotlib.ticker.NullFormatter())

create custom text labels centered between major tick marks

major_locs = major_locator()

for i in range(1,len(major_locs)):
x_last,x = major_locs[i-1],major_locs[i]
ax.text(0.5*(x+x_last), -0.04, major_formatter(x, i),
transform=transLabels, horizontalalignment=‘center’)

When “zooming around” an interactive plot, however, my custom labels get pushed

off into the margins. I’m guessing I need to put them in a clip box somehow. Any hints?

Thanks!
Alex