栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

用seaborn绘制时间序列数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用seaborn绘制时间序列数据

我不认为’tsplot’能处理你的数据。这个它对输入数据所做的假设是,你已经采样了相同的数据
每个时间点的单位(尽管有些时间点可能会丢失)单位)。例如,假设你每天测量同一个人的血压
一个月,然后你想用条件(其中“条件”变量可能是他们的饮食)。

tsplot可以做到这一点,用一个看起来像
sns.tsplot图(df,time=“day”,unit=“person”,condition=“diet”,
value=“血压”)`这种情况不同于在不同的
每天从每组中随机抽取一部分并测量血压。从你给出的例子来看,你的数据似乎是
像这样的结构。然而,要想把matplotlib和熊猫结合起来并不难我想你想干什么就干什么:

# Read in the data from the stackoverflow questiondf = pd.read_clipboard().iloc[1:]# Convert it to "long-form" or "tidy" representationdf = pd.melt(df, id_vars=["date"], var_name="condition")# Plot the average value by condition and dateax = df.groupby(["condition", "date"]).mean().unstack("condition").plot()# Get a reference to the x-points corresponding to the dates and the the colorsx = np.arange(len(df.date.unique()))palette = sns.color_palette()# Calculate the 25th and 75th percentiles of the data# and plot a translucent band between themfor cond, cond_df in df.groupby("condition"):    low = cond_df.groupby("date").value.apply(np.percentile, 25)    high = cond_df.groupby("date").value.apply(np.percentile, 75)    ax.fill_between(x, low, high, alpha=.2, color=palette.pop(0))


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/637995.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号