我不认为’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))


