Q:

Pyplot ticks at values divisible by automatic interval?

Is there a way how to force pyplot (matplotlib) to have ticks at values divisible by automatic interval of ticks?
I really like that pyplot can adjust interval of ticks automatically based on data so I don't have to care about it. But I would really like it does use values divisible by that interval.
For example if it decides that interval is 5, it should use values 5,10,15,20... and not 4,9,14,19 like in the example below. How can I easily fix it?

A:

You can locate your ticks anywhere you want using matplotlib.ticker.Locator classes. Specifically in your case I guess you'd like to use MultipleLocator. Just add in your program
from matplotlib.ticker import MultipleLocator
ax = plt.gca()
ax.get_xaxis().set_major_locator(MultipleLocator(base=5))

and you'll be all set.
UPDATE:
To get the base, you can check the default AutoLocator tick positions (after the call to plt.plot) and get the difference between any of them lying next to each other:
ticks = ax.get_xticks()
base = ticks[1] - ticks[0]

