我运行了多重回归并将系数和标准误差存储到这样的数据框中:
我想制作一个图表来显示每个组的系数随时间的变化情况,如下所示:
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(14,8))
sns.set(style= "whitegrid")
sns.lineplot(x="time", y="coef",
hue="group",
data=eventstudy)
plt.axhline(y=0 , color='r', linestyle='--')
plt.legend(bbox_to_anchor=(1, 1), loc=2)
plt.show
plt.savefig('eventstudygraph.png')
哪个产生:
但我想使用我的主数据集中的“stderr”数据来包含错误栏。我想我可以使用“plt.errorbar”来做到这一点。但似乎无法弄清楚如何让它发挥作用。目前,我尝试添加 'plt.errorbar 行并尝试不同的迭代:
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(14,8))
sns.set(style= "whitegrid")
sns.lineplot(x="time", y="coef",
hue="group",
data=eventstudy)
plt.axhline(y=0 , color='r', linestyle='--')
plt.errorbar("time", "coef", xerr="stderr", data=eventstudy)
plt.legend(bbox_to_anchor=(1, 1), loc=2)
plt.show
plt.savefig('eventstudygraph.png')
如您所见,它似乎在图表中创建了自己的组/线。如果我只有一组,我想我会知道如何使用“plt.errorbar”,但我不知道如何让它适用于 3 个组。有什么方法可以制作 3 个版本的“plt.errorbar”,这样我就可以分别为每个组创建错误栏了吗?或者有更简单的东西吗?
慕妹3146593
相关分类