如何根据某些行(如datetime或location)的值限制seaborn/sns.lineplot中的“数据”?

2024-03-28 22:11:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个从1970年到2019年的降雨数据集,包含位置、Y、M、D列

我可以用它来描绘

ax = sns.lineplot(x="Month", y="Rainfall", hue="Year", data=df)

但我希望输出图仅限于特定年份或位置,因为如果我按照色调绘制所有年份,那么它就会变得一团糟。 像这样的,

ax = sns.lineplot(x="Month", y="Rainfall", hue="Dayofyear", data=df[(df.Station == 'Dhaka') & (df.Year == 1970])

但当我这样做时,什么也不会发生。这是输出https://i.stack.imgur.com/4KJmE.png

但是当我这样设置时(df.Year>;=1977),我得到了一个输出

ax = sns.lineplot(x="Month", y="Rainfall", hue="Dayofyear", data=df[(df.Station == 'Dhaka') & (df.Year >= 1977)])

像这样:https://i.stack.imgur.com/kwWUU.png

这里是否有一种简单的方法来指定“数据”。比如,我想指定一系列年份,比如1970年<;年份<;1999 ?


Tags: 数据httpsdfdataaxyearhue年份