I want to make a graph with Matplotlib. I want the X-axis ticks to be every 2 hours and aligned with my data. Using ser_major_locator(mdates.MinuteLocator()) may accept interval=120 to make ticks every two hours, but this does not align with the data. MinuteLocator() will accept a range to byminute which satisfies the offset desire, but this will place ticks every hour. Here's an example: import matplotlib.pyplot as plt import matplotlib.dates as mdates from datetime import datetime, timedelta start_time = datetime(2025, 9,15, 12, 37) t = [start_time, start_time + timedelta(hours=2), start_time + timedelta(hours=4)] values = [4,2,7] plt.plot(t,values) ax = plt.gca() ax.xaxis.set_major_locator(mdates.MinuteLocator(interval=120)) plt.grid(True) plt.show() Continue reading...