Editing the date formatting of x-axis tick labels
In short: import matplotlib.dates as mdates myFmt = mdates.DateFormatter(‘%d’) ax.xaxis.set_major_formatter(myFmt) Many examples on the matplotlib website. The one I most commonly use is here
In short: import matplotlib.dates as mdates myFmt = mdates.DateFormatter(‘%d’) ax.xaxis.set_major_formatter(myFmt) Many examples on the matplotlib website. The one I most commonly use is here
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)) Read the official docs: https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.MaxNLocator
You could explicitly set where you want to tick marks with plt.xticks: plt.xticks(np.arange(min(x), max(x)+1, 1.0)) For example, import numpy as np import matplotlib.pyplot as plt x = [0,5,9,10,15] y = [0,1,2,3,4] plt.plot(x,y) plt.xticks(np.arange(min(x), max(x)+1, 1.0)) plt.show() (np.arange was used rather than Python’s range function just in case min(x) and max(x) are floats instead of ints.) … Read more