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))
More Related Contents:
- Format axis offset-values to whole numbers or specific number
- Change grid interval and specify tick labels
- Changing the “tick frequency” on x or y axis in matplotlib
- Changing the tick frequency on the x or y axis
- Plot logarithmic axes
- Editing the date formatting of x-axis tick labels
- X-axis tick labels are too dense when drawing plots
- Date ticks and rotation [duplicate]
- Change tick frequency on X (time, not number) frequency
- How to make IPython notebook matplotlib plot inline
- How to find the exact intersection of a curve (as np.array) with y==0?
- stack bar plot in matplotlib and add label to each section
- How to change the figure size of a seaborn axes or figure level plot
- Which is the recommended way to plot: matplotlib or pylab?
- Remove xticks in a matplotlib plot?
- Matplotlib yaxis range display using absolute values rather than offset values?
- How to draw a rectangle over a specific region in a matplotlib graph
- Fit a gaussian function
- Creating intersecting images in matplotlib with imshow or other function
- use format with tex fraction expression in matplotlib python
- Automatically Rescale ylim and xlim in Matplotlib
- How to overplot a line on a scatter plot in python?
- matplotlib does not show my plot although I call pyplot.show()
- setting spacing between grouped bar plots in matplotlib
- matplotlib savefig() size control
- MonthLocator in Matplotlib
- How to draw grid lines behind matplotlib bar graph
- How to create a legend for 3D bar in matplotlib?
- How to remove/omit smaller contour lines using matplotlib
- Python: Matplotlib avoid plotting gaps