使用 seaborn 从外部数据源绘制标准偏差
Plot standard deviation from external datasource using seaborn
我正在尝试通过 seaborn 可视化一个线图,我想在其中绘制一列的平均值和标准偏差。由于我使用的是大文件(有数百万行),该图需要一段时间才能加载。
为了减少计算时间,我预先计算了列的平均值和相应的标准差。随后,我使用这个预先计算的数据作为线图的输入,而不是提供完整的 Pandas 数据框。
这是我目前使用的代码:
df = open_pickle("data/experiment")
sns.lineplot(x="rho", y="wait_time_mean", hue="c", style="service_type", data=df)
这只会显示平均值。我想知道是否可以手动为 seaborn 提供标准偏差值。
sns.lineplot
returns 绘图的 Axes 对象,然后可用于在其上绘制。假设您的标准偏差也在 df
中,您可以按以下方式调整代码,现在使用 matplotlib 函数 fill_beetween
:
df = open_pickle("data/experiment")
ax = sns.lineplot(x="rho", y="wait_time_mean", hue="c", style="service_type", data=df)
ax.fill_between(df["rho"], y1=df["wait_time_mean"] - df["wait_time_std"], y2=df["wait_time_mean"] + df["wait_time_std"], alpha=.5)
我正在尝试通过 seaborn 可视化一个线图,我想在其中绘制一列的平均值和标准偏差。由于我使用的是大文件(有数百万行),该图需要一段时间才能加载。
为了减少计算时间,我预先计算了列的平均值和相应的标准差。随后,我使用这个预先计算的数据作为线图的输入,而不是提供完整的 Pandas 数据框。
这是我目前使用的代码:
df = open_pickle("data/experiment")
sns.lineplot(x="rho", y="wait_time_mean", hue="c", style="service_type", data=df)
这只会显示平均值。我想知道是否可以手动为 seaborn 提供标准偏差值。
sns.lineplot
returns 绘图的 Axes 对象,然后可用于在其上绘制。假设您的标准偏差也在 df
中,您可以按以下方式调整代码,现在使用 matplotlib 函数 fill_beetween
:
df = open_pickle("data/experiment")
ax = sns.lineplot(x="rho", y="wait_time_mean", hue="c", style="service_type", data=df)
ax.fill_between(df["rho"], y1=df["wait_time_mean"] - df["wait_time_std"], y2=df["wait_time_mean"] + df["wait_time_std"], alpha=.5)