简体   繁体   English

在 seaborn 上绘制 y 轴网格和 kdeplot 之间的交点

[英]Plot intersection between y-axis grid and kdeplot on seaborn

I have created the following plot using seaborn kdeplot and customizing the gridlines.我使用 seaborn kdeplot 并自定义网格线创建了以下图。 在此处输入图片说明

sns.set_style('whitegrid')
cdf_accuracy = sns.kdeplot(eval_df['accuracy'], cumulative=True)
cdf_accuracy.yaxis.set_major_locator(ticker.MultipleLocator(0.25))
cdf_accuracy.xaxis.set_major_locator(ticker.MultipleLocator(10))

However, I would like to show the gridlines on the x-axis just on the points were the y-axis gridlines intersect the plot.但是,我想仅在 y 轴网格线与绘图相交的点上显示 x 轴上的网格线。 There is a way to do this?有没有办法做到这一点?

Thanks for your answers谢谢你的回答

As long as your characteristic is monotonic, which should be given with a cumulative dataset, you could simply use interpolation on the y-values:只要您的特征是单调的,应该用累积数据集给出,您就可以简单地对 y 值使用插值:

import numpy as np

y_intrsct = [.25, .5, .75]
x_intrsct = np.interp(y_intrsct, y_data, x_data)

which results in这导致

array([67.69792378, 83.24194722, 92.24041857])

在此处输入图片说明

plotted with the following code:用以下代码绘制:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(x_data, y_data)
ax.set_yticks(np.linspace(0, 1, 5))
ax.grid(axis='y')
ax.vlines(x_intrsct, *ax.get_ylim())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM