用置信区间python绘制比值比

问题描述

我试图以这种方式表示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])的信息。如何绘制置信区间?预先感谢。

解决方法

我与您分享我的代码,它用于垂直绘图,但您可以更改轴。我有一个表格,其中包含 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,"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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...