Matplotlib: How to force integer tick labels?

This should be simpler:

(from https://scivision.co/matplotlib-force-integer-labeling-of-axis/)

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

The following solution by simply casting the index i to string worked for me:

    import matplotlib.pyplot as plt
    import time

    datay = [1,6,8,4] # Just an example
    datax = []
    
    # In the following for loop datax in the end will have the same size of datay, 
    # can be changed by replacing the range with wathever you need
    for i in range(len(datay)):
        # In the following assignment statement every value in the datax 
        # list will be set as a string, this solves the floating point issue
        datax += [str(1 + i)]

    a = plt

    # The plot function sets the datax content as the x ticks, the datay values
    # are used as the actual values to plot
    a.plot(datax, datay)

    a.show()