1

I've been on here all day trying to figure out how I can change the tick labels on the x-axis. I'm exclusively working with large financial time series, so I can't just create small little tick lists. If possible I'd like the axis to show, for example, March 2016 (or Mar 16) instead of 03-2016.

I'd like to write something that is easy to understand (I'm a python noob), and that I can easily copy->paste->manipulate for different datasets. For example, is it possible to label every other tick (or every 4 ticks etc etc)?

Here's what I have so far:

years = mdates.YearLocator()
months = mdates.MonthLocator()
days = mdates.DayLocator()
fmt = mdates.DateFormatter('%Y')

fig, ax = plt.subplots(figsize = (20,10))
x = SP500_Futures_Net_Positioning1.index
y = SP500_Futures_Net_Positioning1[0]
ax.bar(x,y,width = 10, color = 'deepskyblue')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_minor_locator(months)
ax.xaxis.set_major_formatter(fmt)
ax.grid(False)

plt.show()

Futures Positioning Graph

If you know any good tutorials on this please send them my way.

Thanks everyone!!

Tom
  • 87
  • 2
  • 7
  • The code snippet you have in the question is well suited for your needs. It's not clear what exactly the problem is. To change the tick locations you may use different arguments to the locators (simply look at the documentation) and to change the date format you may specify a different format, e.g. "%b %Y" for month year format. – ImportanceOfBeingErnest Jun 25 '17 at 08:18

0 Answers0