gpt4 book ai didi

python - 如何注释(xy 坐标)nd.array 的百分位数图?

转载 作者:行者123 更新时间:2023-12-01 08:08:16 26 4
gpt4 key购买 nike

我正在尝试绘制 nd.array 的百分位数,并且我想考虑肘点以上的所有点。因此,如果我的肘点位于 83%,我想获取第 83 个百分位点的 y 坐标(因此出现问题),因此将其设置为阈值并获取高于该阈值的所有点。

我尝试了.annotate,但卡住了。请帮忙。

from matplotlib import mlab
p = np.array([0,10,20,30,40,50,60,70,80,83,84,85,90])
pchange=np.array([1,2,3,6,5,8,9,7,4,5,6,9,8,5,2,3,6,4,25,36,14,65,98,98,54,25,26,23,24,27,28,26,24,262,1,156,31,51,351,651,35,153,135,1,5,31,68,3,5,61,354,685,16,813,51,685,681,35,68,135,1685,1354,135,415,135,153,413,513,56,513,213,651,354,51,35,135,135,135,438,535,468,53,8,35,4,648,468,535,468,46,8,498,498,749,8798,798,79,8798,7,979,879,8,97,9,79,7,9798,798,78,979,87,974,65,498,46,8,98,79,878,978,65,984,98,49,9,569,949,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888])
perc = mlab.prctile(pchange, p)
print(perc)
plt.plot(perc)
plt.plot((len(perc)-1) * p/100., perc, 'ro')
plt.xticks((len(perc)-1) * p/100., map(str, p))
for a,b in enumerate(pchange):
plt.annotate(b,(perc[a],p[a]),xytext=(perc[a],p[a]))
plt.show()

最佳答案

根据当前信息,我不完全确定您想要什么。你的x轴不直观。当我测试您的代码时,我只收到注释错误,因为您应该循环遍历百分比而不是总数据。请参阅下面的代码和 annotate example寻求更多帮助。如果这不是您想要的,请澄清您的问题,我将更新我的答案。

import numpy as np
from matplotlib import pyplot as plt

p = np.array([0,10,20,30,40,50,60,70,80,83,84,85,90])

pchange=np.array([1,2,3,6,5,8,9,7,4,5,6,9,8,5,2,3,6,4,25,36,14,65,98,98,54,25,26,23,24,27,28,26,24,262,1,\
156,31,51,351,651,35,153,135,1,5,31,68,3,5,61,354,685,16,813,51,685,681,35,68,135,1685,1354,\
135,415,135,153,413,513,56,513,213,651,354,51,35,135,135,135,438,535,468,53,8,35,4,648,468,535,\
468,46,8,498,498,749,8798,798,79,8798,7,979,879,8,97,9,79,7,9798,798,78,979,87,974,65,498,46,8,\
98,79,878,978,65,984,98,49,9,569,949,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,\
888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,888,])

perc = np.percentile(pchange,p)


plt.plot(p, perc)
plt.plot(p, perc, 'ro')

for a,b in enumerate(perc):
plt.annotate('%2.2f'%b,(p[a],perc[a]),xytext=(p[a],perc[a]))
#Note you may want to add an offset to your x,y since labeling every point
# makes the plot cluttered. I added %2.2f to truncate the values some.

plt.show()

结果如下图

enter image description here

关于python - 如何注释(xy 坐标)nd.array 的百分位数图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55426485/

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