[英]How Can i Get the X axis Value for the Distributions peak y value in a seaborn distplot?
So i have a frequency distribution plot that looks like this:所以我有一个看起来像这样的频率分布图:
image of the Desired point所需点的图像
an i need the x value corresponding to the peak of the y value.我需要与 y 值的峰值相对应的 x 值。 How can i get it for the plotting code?
我怎样才能得到它的绘图代码?
seaborn.distplot('TheSeries',bins = 30, ax=axes[0][1])
Can someone explain how i can get that corresponding value for this and similar cases?有人可以解释我如何为这种情况和类似情况获得相应的价值吗?
You can extract the coordinates of the kde curve from ax.lines[-1]
and use np.argmax()
to find the mode of the curve.您可以从
ax.lines[-1]
提取 kde 曲线的坐标并使用np.argmax()
来查找曲线的众数。
Note the in the latest seaborn version distplot
has been deprecated.请注意,最新的 seaborn 版本
distplot
已被弃用。 Here histplot
with kde=True
would be its replacement.这里带有
kde=True
histplot
将是它的替代品。
from matplotlib import pyplot as plt
import numpy as np
import seaborn as sns
samples = np.random.randn(300) ** 2 * 50
ax = sns.histplot(samples, bins=30, kde=True, color='skyblue')
kdeline = ax.lines[0]
xs = kdeline.get_xdata()
ys = kdeline.get_ydata()
mode_idx = np.argmax(ys)
ax.vlines(xs[mode_idx], 0, ys[mode_idx], color='tomato', ls='--', lw=2)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.