Just adding to Floriaan's answer, I had noticed that the function did not work well for inputs round_to greater than 1, so I added a small checkup:
def calculate_ticks(ax, ticks, round_to=0.1, center=False):
upperbound = np.ceil(ax.get_ybound()[1]/round_to)
lowerbound = np.floor(ax.get_ybound()[0]/round_to)
dy = upperbound - lowerbound
# The added part:
if round_to > 1:
fit = np.floor(dy/(ticks - 1))
else:
fit = np.floor(dy/(ticks - 1)) + 1
dy_new = (ticks - 1)*fit
if center:
offset = np.floor((dy_new - dy)/2)
lowerbound = lowerbound - offset
values = np.linspace(lowerbound, lowerbound + dy_new, ticks)
return values*round_to