my matplotlib version is 3.0.0
import matplotlib.pyplot as plt
import matplotlib.mdates as mdates
import pandas as pd
years = range(2016, 2025)
fig, axes = plt.subplots(len(years), 1, figsize=(10, 20))
for ax, year in zip(axes, years):
common_idx = pd.date_range(str(year), str(year+1), closed='left')
s = pd.Series(42, common_idx)
s.plot(ax=ax)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.set_title(year)
fig.set_tight_layout(True)
the above code is mcve. and the below is the result.
why do graphs in 2016, 2018, 2019, 2020, 2022, 2023 put the first tick on the wrong location? I can't even find any pattern (like leap year)...