海洋线图表明活动趋势

发布于 2025-02-06 10:44:23 字数 962 浏览 2 评论 0原文

Seaborn线路图上,我想指出时间序列数据的趋势,最好使用不同的颜色。

例如,获取此假数据:

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')

linePlot上,这会产生以下图:

sns.lineplot(data=df, x = df['date'], y='max', )
plt.xticks(rotation=45)

“在此处输入图像说明”

所以我想指出2017-01之间的时间序列趋势2017-08,以使该图的背景为绿色,并标记为“开始”和“类似于下图,但在指示的区域中插入绿色背景)。

On a seaborn lineplot, I would like to indicate trend in a time-series data, preferably using different colours.

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:

sns.lineplot(data=df, x = df['date'], y='max', )
plt.xticks(rotation=45)

enter image description here

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).
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望喜 2025-02-13 10:44:24

您可以使用 >:

ax = sns.lineplot(data=df, x = df['date'], y='max', )
ax.axvspan('2017-01', '2017-08', color='g', alpha=0.1)

输出:

“在此处输入图像描述”

与不同的zorder

ax.axvspan('2017-01', '2017-08', color='g', alpha=0.5, zorder=0)

output:

“在此处输入图像说明”

You can use ax.axvspan:

ax = sns.lineplot(data=df, x = df['date'], y='max', )
ax.axvspan('2017-01', '2017-08', color='g', alpha=0.1)

output:

enter image description here

alternative with a different zorder:

ax.axvspan('2017-01', '2017-08', color='g', alpha=0.5, zorder=0)

output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文