[英]seaborn lineplot time-series indicating trend in activity
On a seaborn
lineplot, I would like to indicate trend in a time-series data, preferably using different colours.在
seaborn
线图上,我想指示时间序列数据的趋势,最好使用不同的颜色。
For example, taking this fake data:例如,取这个假数据:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame(np.random.randint(100, size=50), columns=['max'])
df['day'] = pd.date_range('2016-1-1', periods=50, freq='SMS')#freq='W')
df['date'] = df['day'].dt.strftime('%Y-%m')
On a lineplot
this produces the following figure:在线
lineplot
,这会产生下图:
sns.lineplot(data=df, x = df['date'], y='max', )
plt.xticks(rotation=45)
So I would like to indicate the trend in time series between 2017-01
and 2017-08
such that the plot's background in this area is in green, with begin and end marked (similar to the figure below, but inserting green background in the area indicated).所以我想指出
2017-01
和2017-08
之间的时间序列趋势,使得该区域的情节背景为绿色,并标记开始和结束(类似于下图,但在该区域插入绿色背景表明的)。
You can use ax.axvspan
:您可以使用
ax.axvspan
:
ax = sns.lineplot(data=df, x = df['date'], y='max', )
ax.axvspan('2017-01', '2017-08', color='g', alpha=0.1)
output:输出:
alternative with a different zorder
:用不同的
zorder
替代:
ax.axvspan('2017-01', '2017-08', color='g', alpha=0.5, zorder=0)
output:输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.