matplotlib 영역표시Published by onesixx on 24-03-1424-03-14 import numpy as np import random dd = pd.DataFrame({'daytime_ts':pd.date_range('2023-10-25', periods=13, freq='H'), 'option': [1,2,3,3,3,2,2,3,3,1,1,1,4], 'y': random.sample(range(10, 101), 13)}) dd.loc[:, 'chage_grp'] = (dd['option'] != 3).cumsum() chage_grps = dd[dd['option'] == 3].groupby('chage_grp')['daytime_ts'].agg(['min', 'max']) fig, ax = plt.subplots() ax.plot(dd['daytime_ts'], dd['y']) for _, row in chage_grps.iterrows(): ax.axvspan(row['min'], row['max'], color='skyblue', alpha=0.3) plt.show() Categories: Uncategorized onesixx Blog Owner Subscribe Notify of new follow-up comments new replies to my comments Label {} [+] Name* Email Δ Label {} [+] Name* Email Δ 0 Comments Inline Feedbacks View all comments