How to force the Y axis to only use integers

Here is another way:

from matplotlib.ticker import MaxNLocator

ax = plt.figure().gca()
ax.yaxis.set_major_locator(MaxNLocator(integer=True))

Leave a Comment