I'm using pandas inbuilt .plot
command to plot stuff some long-ish time series.
But my date ticks always are years ending in 9 by default.
Why is that so, and how can I change it? Years ending in 0 would look much nicer.
Trying to set the window of the axis with plt.xlim('1966', '2013')
or something like this also does not do anything about plots fetish for years ending in 9 (and 4, if you "zoom in", as shown above).
It also does not seem to have anything to do with the start and end of the dates in the source dataframe.
here is a minimal, empty, example:
dfdates = pd.date_range('01/01/1942', '01/01/2018', freq = 'MS')
dfzeros = np.zeros((len(dfdates)))
header_test = pd.MultiIndex.from_product([['zero'],['zero'], ['zero'], ['zero'], ['zero'], ['zero']], names = ['stuff1', 'stuff2', 'stuff3', 'stuff4', 'stuff5', 'stuff6'])
Big_df = pd.DataFrame(dfzeros, index = dfdates, columns = header_test)
Big_df.plot()
plt.show()
…And this results in this for me:
And I cant change the 9's at the end, no matter if I set a window with plt.xlim
or if I change the start and end years, months or days of dfdates
, so it's not something easy as "start of the dataframe + 10 years" or similar, and my large header also does not affect those.
I probably could set more sensible ticks per hand, but I'd rather know why it is so hell bent on using years with 9 at the end.
EDIT
So here is what happens when I plot, using @lanery's answer:
Note the double ticks in the area of the plot where I specified the custom ticks (starting at 1965).
All my dataframes start at 1940, but many are empty, to a certain point where I start to get data, depending on the dataset in question. I can cut this off with
plt.xlim('1965','2015')
, but I left it in in this plot, to show whats happening.