Q:

python - how to set ticks on x-axis at specific location

On my x-axis I have days (for example 0-5000 days). Now I would like to divide this into years by dividing by 365 days so that from 0-365 it would say 2016, 366 - 2*365: 2017 etc.
What's the best way to do this? 
Is there something like ax.tickValues(xrange(0,5000,365))?

A:

Following is one example of how you could do it. The idea is following: First generate the tick-labels (years) you want to show starting from 2016. Here int(np.ceil(5000/365)) just gives you the number of years to display on the axis. Next, you generate the position where to put these ticks. Currently I am using centre of 0-365, 365-730, etc. as the location of ticks because you want 0-365 labeled as 2016 and so on.
You can adapt the below solution for your problem.
from matplotlib.ticker import AutoMinorLocator

fig, axes = plt.subplots(figsize=(10, 6))

x = range(3000)
plt.plot(x,x)

tcks = [2016+i for i in range(int(np.ceil(3000/365)))]
locs = [365*i for i in range(int(np.ceil(3000/365)))]
plt.xticks(locs, tcks)
axes.xaxis.set_minor_locator(AutoMinorLocator(12))

