gpt4 book ai didi

Python - 注释 True 值(并使用其他值)

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:41 25 4
gpt4 key购买 nike

我有一个值的数据框,我用它来绘制具有置信区间的散点图/折线图:

数据框(sqlDF2)是这样的:

Statu   Total   Outside   Success   Pred   Upper95    Lower95      Upper99    Lower99
Org
A 391 True 38 0.35064 0.398903 0.302377 0.423034 0.278245
B 360 False 30 0.343464 0.393519 0.293408 0.418546 0.268381
C 271 False 29 0.319606 0.37626 0.262951 0.404587 0.234624
D 247 True 22 0.312089 0.371053 0.253125 0.400535 0.223643
...

我的代码是:

import seaborn as sns
import matplotlib.pyplot as plt

# Initialize Figure and Axes object
fig, ax = plt.subplots(figsize=(15,8))

# Load in the data
data = sqlDf2

y = data['Success'].values
x = data['Total'].values
up95 = (data['Upper95'].values)*100
low95 = (data['Lower95'].values)*100
up99 = (data['Upper99'].values)*100
low99 = (data['Lower99'].values)*100
middleLine = (data['Pred'].values)*100
holdOrg = sqlDf2.index.tolist()



# Create plot
sns.regplot(x="Total", y="Success", data=data,fit_reg=False, ax=ax)
plt.plot(x,up95, linewidth=2)
plt.plot(x,low95, linewidth=2)
plt.plot(x,up99, linewidth=2)
plt.plot(x,low99, linewidth=2)
plt.ylim(0, 100)
plt.margins(x=0)

# Show plot
plt.show()

仅当'Outside'列为True时,我才尝试注释散点图中的值。目前每个点都被注释了:

enter image description here

我还希望注释的值不是 xy,而是来自“holdOrg”的值。

这容易做到吗?

最佳答案

如果您有三个列表,x,y,z,您可以使用以下标签来标记 xy 给定位置处的点z 通过循环这三个列表。

x = [1,2,3]
y = [4,5,6]
z = ["A","B","C"]
#annotation
for i,j, label in zip(x,y,z):
ax.annotate(label,xy=(i,j))

关于Python - 注释 True 值(并使用其他值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48521291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com