matplotlib 영역표시

Published by onesixx on

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: visualization

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x