用置信区间python绘制比值比

时间:2020-09-10 14:11:43

标签: python plot confidence-interval

我试图以这种方式表示python中的优势比:

ax = sns.scatterplot(data=df_result, x="odd_ratio", y="iso")
plt.axvline(1.0, color='black', linestyle='--')

enter image description here

但是我希望每个比值比都有水平线来表示置信区间。 在我的数据帧df_result中,有关于下限和上限(df_result['lower_conf]df_result['upper_conf])的信息。如何绘制置信区间?预先感谢。

1 个答案:

答案 0 :(得分:1)

我与您分享我的代码,它用于垂直绘图,但您可以更改轴。我有一个表格,其中包含 5%、95% 和不同列中的 OR 值

sns.set_style("whitegrid")
fig, ax = plt.subplots(figsize=(7, 5))
ax.set_yscale("log")
ax.axhline(1, ls='--', linewidth=1, color='black')

n = 0
for index, i in df.iterrows():
    x = [n,n]
    y = [i["5%"], i["95%"]]
    ax.plot(x, y, "_-", markersize = 15, markeredgewidth= 3, linewidth = 3, color=sns.color_palette("muted")[n])

    x = [n]
    y = [i["Odds Ratio"]]
    ax.plot(x, y, "o", color=sns.color_palette("muted")[n], markersize = 10)
    n += 1

ax.set_xlabel("")
ax.set_ylabel("Odds Ratio")
ax.set_xticklabels(["", "Resistant", "Focal Epilepsy", "> 3 seizures/month", "Polytherapy", "DDD > 1", "Adverse effects"], rotation=45)

result

相关问题