【问题标题】:Plot odds ratio with confidence interval python用置信区间python绘制优势比
【发布时间】:2020-09-10 14:11:43
【问题描述】:

我正在尝试以这种方式在 python 中表示优势比:

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

但我希望每个优势比都有水平条来表示置信区间。 在我的数据框df_result 中,我有关于下限和上限的信息(df_result['lower_conf]df_result['upper_conf])。如何绘制置信区间?提前致谢。

【问题讨论】:

    标签: python plot confidence-interval


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-01
      • 2020-11-16
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      相关资源
      最近更新 更多