how to highlight weekends in matplotlib plots?
问题 For a simple time series: import pandas as pd df = pd.DataFrame({'dt':['2020-01-01', '2020-01-02', '2020-01-04', '2020-01-05', '2020-01-06'], 'foo':[1,2, 4,5,6]}) df['dt'] = pd.to_datetime(df.dt) df['dt_label']= df['dt'].dt.strftime('%Y-%m-%d %a') df = df.set_index('dt') #display(df) df['foo'].plot() x =plt.xticks(ticks=df.reset_index().dt.values, labels=df.dt_label, rotation=90, horizontalalignment='right') How can I highlight the x-axis labels for weekends? edit Pandas Plots: Separate color