import matplotlib.pyplot as plt from matplotlib.ticker import MaxNLocator #... ax = plt.figure().gca() #... ax.xaxis.set_major_locator(MaxNLocator(integer=True))