如何在Python中找到KDE直方图的模式(数字)
我想确定直方图中最高选择的X值。
打印直方图的代码:
fig=sns.displot(data=df, x='degrees', hue="TYPE", kind="kde", height=6, aspect=2)
plt.xticks(np.arange(10, 20, step=0.5))
plt.xlim(10, 20)
plt.grid(axis="x")
直方图和值需要(实际上,我想要所有4个):
I want to determine the X value that has the highest pick in the histogram.
The code to print the histogram:
fig=sns.displot(data=df, x='degrees', hue="TYPE", kind="kde", height=6, aspect=2)
plt.xticks(np.arange(10, 20, step=0.5))
plt.xlim(10, 20)
plt.grid(axis="x")
Histogram and value wanted (in fact, I would like all 4):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用
matplotlib
方法来检索行的基础X和Y数据。如果您使用
strendot
,如摘录中,那么这是一个带有两个组的玩具数据集上的解决方案价值。x
值是首先找到最大的y
值,然后使用该值的索引来找到x
值。如果您决定使用
kdeplot
,则语法略有不同:You will need to retrieve the underlying x and y data for your lines using
matplotlib
methods.If you are using
displot
, as in your excerpt, then here is a solution on a toy dataset with two groups that both prints thex
value and plots a vertical line for that value. Thex
value is obtained by first finding the largesty
value and then using the index of that value to locate thex
value.If you decide to use
kdeplot
, then the syntax is slightly different:Alexk的答案非常轻微扩展:您可以获得虚线的颜色,以匹配这样的内核的颜色:
Very slight expansion on AlexK's answer: you can get the color of the dotted vertical lines to match the colors of the kernels like this: