The closest post I found on SO is as follows (Date ticks and rotation in matplotlib), but still doesnt solve my issue. I need to align the years to appear directly below the red square boxes. I have tried autoformat and align keywords, but nothing works. Anyone can show what am I doing wrong?
dates = [df_filtered.release_date.min(),wm_director.release_date.min(),wd.loc[7283,'Year'],wd.loc[9125,'Year'],
wd.loc[10127,'Year']]
texts = ['1st movie released','1st movie directed by woman','1st Best Director nomination','Best Director won',
'2nd Best Director Nomination']
fig, ax = plt.subplots(figsize=(14,1))
ax.plot((dates[0],dates[-1]),(0,0),'k',alpha=0.3)
for i, (text,date) in enumerate(zip(texts,dates)):
ax.scatter(date,0,marker='s', s=100,color='crimson')
ax.text(date,0.01,text,rotation=45,va="bottom",fontsize=14)
ax.set_xticklabels([i.year for i in dates])
ax.yaxis.set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.grid('off')
ax.patch.set_facecolor('white')
ax.get_yaxis().set_ticklabels([])
plt.show()
The list of dates are obtained by extracting the relevant rows from various dataframes, with values already converted to datatime format.