【发布时间】:2018-01-30 10:14:33
【问题描述】:
我有一个值数据框,我用它来绘制带有置信区间的散点图/折线图:
数据框(sqlDF2)是这样的:
Statu Total count Success Pred Upper95 Lower95 Upper99 Lower99
Org
A 391 391 38 0.35064 0.398903 0.302377 0.423034 0.278245
B 360 360 30 0.343464 0.393519 0.293408 0.418546 0.268381
C 271 271 29 0.319606 0.37626 0.262951 0.404587 0.234624
D 247 247 22 0.312089 0.371053 0.253125 0.400535 0.223643
...
我绘制图形的代码是:
y = sqlDf2['Success'].values
x = sqlDf2['Total'].values
up95 = (sqlDf2['Upper95'].values)*100
low95 = (sqlDf2['Lower95'].values)*100
up99 = (sqlDf2['Upper99'].values)*100
low99 = (sqlDf2['Lower99'].values)*100
middleLine = (sqlDf2['Pred'].values)*100
plt.figure(figsize=(15,8))
plt.ylim(0, 100)
plt.margins(x=0)
plt.scatter(x,y,marker='o',c='white',edgecolors = 'black', alpha=.5)
plt.plot(x,up95, 'red', linestyle=':', dashes=(1, 5), linewidth=1)
plt.plot(x,low95, 'red', linestyle=':', dashes=(1, 5), linewidth=1)
plt.plot(x,up99, 'red', linestyle=':', dashes=(1, 5), linewidth=1)
plt.plot(x,low99, 'red', linestyle=':', dashes=(1, 5), linewidth=1)
plt.plot(x,middleLine, 'red', linestyle='-', dashes=(1, 2), linewidth=1)
plt.show()
图表如下所示:
我想要做的是用“Org”的值对高于和低于 99% 置信区间的值进行注释。有没有一种简单的方法可以计算出 Python 中两行上下的值?
谢谢
【问题讨论】:
标签: python pandas matplotlib