【发布时间】:2021-06-09 08:34:00
【问题描述】:
这里是新的,所以放置了超链接。我的数据框看起来像这样。
HR ICULOS SepsisLabel PatientID
100.3 1 0 1
117.0 2 0 1
103.9 3 0 1
104.7 4 0 1
102.0 5 0 1
88.1 6 0 1
访问整个文件here。我想要的是在基于 SepsisLabel 的 HR 图上添加一个标记(参见文件)。例如,在 ICULOS = 249 时,脓毒症标签从 0 变为 1。我想在图表上显示此时,脓毒症标签发生了变化。我能够使用此代码计算位置:
mark = dummy.loc[dummy['SepsisLabel'] == 1, 'ICULOS'].iloc[0]
print("The ICULOS where SepsisLabel changes from 0 to 1 is:", mark)
Output: The ICULOS where SepsisLabel changes from 0 to 1 is: 249
我使用代码绘制了图表:
plt.figure(figsize=(15,6))
ax = plt.gca()
ax.set_title("Patient ID = 1")
ax.set_xlabel('ICULOS')
ax.set_ylabel('HR Readings')
sns.lineplot(ax=ax,
x="ICULOS",
y="HR",
data=dummy,
marker = '^',
markersize=5,
markeredgewidth=1,
markeredgecolor='black',
markevery=mark)
plt.show()
这就是我得到的:Graph。标记应该只在位置 249 上。但它也在位置 0。为什么会这样?有人可以帮帮我吗?
谢谢。
【问题讨论】:
-
您可以尝试
markevery=[mark]给出要标记的位置列表。markevery=249每 249 个位置设置一个标记,从位置 0 开始。 -
太棒了。是否可以在图表上的标记上方/下方添加数字(标记)?
-
使用此错误
-
其他错误,然后是一些拼写错误?
ax.text(mark, dummy.loc[mark, 'HR'], str(dummy.loc[mark, 'ICULOS']) + '\n', ha='center', va='center')?你能解决它们吗? -
拼写错误。现在它完成了。你能简单解释一下这段代码做了什么吗?
标签: python pandas dataframe matplotlib seaborn