I'm having some trouble formatting the x-axis label. I'd like to format the label to show the dates to show the hours but also the date in a YYYY-MM-DD.
Code:
df1.plot.line(y='val1', ax=ax1);
df2.plot.line(y='val1', ax=ax2, legend=False);
plt.suptitle('Some plot ' + str(time[0]) + ' - ' + str(time[1]), fontsize=16, y=1);
#ax1.yaxis.grid(False)
#ax2.yaxis.grid(False)
ax1.grid(linestyle='--', linewidth=0.75)
ax1.spines['right'].set_visible(False)
ax1.spines['top'].set_visible(False)
ax2.set_xlabel('Date-Time')
#ax2.xaxis.set_major_locator(md.MonthLocator())
#ax2.xaxis.set_major_formatter(md.DateFormatter('%Y-%m'))
ax2.spines['right'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax2.grid(linestyle='--', linewidth=0.75)
ax1.legend(bbox_to_anchor=(1.05, 1));
ax2.legend(bbox_to_anchor=(1.05, 1));
ax1.set_title('ClientAB=0');
ax2.set_title('ClientAB=1');
I would like the hours to remain that way but I'd like the Date to change from 16-May to 2022-05-16. I've tried using formatter from mdates but it displayed the year incorrectly like 3226 instead of 2022.
A sample of how the index looks like in my dataframe