我使用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))
但是,我想在 y 轴网格线与绘图相交的点上显示 x 轴上的网格线。有办法做到这一点吗?
感谢您的回答
最佳答案
只要您的特征是单调的(应使用累积数据集给出),您就可以简单地对 y 值使用插值:
import numpy as np
y_intrsct = [.25, .5, .75]
x_intrsct = np.interp(y_intrsct, y_data, x_data)
结果
array([67.69792378, 83.24194722, 92.24041857])
使用以下代码绘制:
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())
关于python - 在seaborn上绘制y轴网格和kdeplot之间的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52985943/