Python – place labels between ticks

matplotlibpython

in matplotlib, how do i place ticks labels between ticks (not below ticks)

for example: when plotting a the stock price over time i would like the x axis minor ticks to display months and the years to show up between consecutive x axis major ticks (not just below the major ticks)

---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---
  jan feb mar apr may jun jul aug sep oct nov dec jan feb mar apr may jun jul aug sep
                       2008                                            2009

Best Answer

Will this do the trick?

enter code here
x = 'j f m a m j j a s o n d j f m a m j j a s o n d'.split()
y = abs(randn(24))
x[6] = 'j\n2008' # replace "j" (January) with ('j' and the appropriate year
x[18] = 'j\n2009'
bar(xrange(len(x)), y, width=0.1)
bar(xrange(len(x)), y, width=0.1)
xticks(xrange(len(x)), x, ha='center')

Barchart with proper labels

Related Topic