본문 바로가기
Python

[python] density plot에서 Peak 값(max or min value) 구하고 표시하기

by Chandler.j 2021. 10. 27.
반응형

fig1. title

#1. kdeplot

#2. get x, y

#3. get max or min

#4. marking


import seaborn as sns
import numpy as np

#1.
ax = sns.kdeplot(th_box_sub2, label='sub2')

#2.
x = ax.lines[0].get_xdata() # Get the x data of the distribution
y = ax.lines[0].get_ydata() # Get the y data of the distribution

#3.
maxid1 = np.argmax(y) # get max in all
maxid2 = np.argmax(y[x<0.59]) # get max in specific range
minid = np.argmin(y[(x>0.56) & (x<0.62)]) # get min in specific range

#4.
plt.plot(x[maxid1], y[maxid1], 'o', label=round(x[maxid1],2), ms=10)
plt.plot(x[maxid2], y[maxid2], 'v', label=round(x[maxid2],2), ms=10)
plt.plot(x[(x>0.56) & (x<0.62)][minid], y[(x>0.56) & (x<0.62)][minid], 'x', label=round(x[(x>0.56) & (x<0.62)][minid],2), ms=10)

plt.legend(fontsize=15)
plt.show()

fig2. output of codeblock


TOP

Designed by 티스토리