从 seaborn 的 kdeplot 中提取等高线水平

extract contour levels from kdeplot in seaborn

我想提取seaborn中kdeplot生成的等高线。我能够使用以下方法导出路径对象:

import numpy as np    
from seaborn import kdeplot
import random
from matplotlib.collections import LineCollection

lA = np.random.normal(1,0.2,1000)
ld = np.random.normal(1,0.2,1000)
kde = kdeplot(x=lA,y=ld)

lines = []
for i in kde.get_children():
    if i.__class__.__name__ == 'LineCollection':
        lines.append(i.get_paths())

我想将轮廓数组提取到 numpy 数组以进行进一步的定量操作。我能够用

提取一些东西
 el=lines[0].pop()
 [i for i in el.iter_segments()]

但我认为这不是我需要的,事实上我需要在数组中绘制完整轮廓

解决方案在iter_segments的关键字中,必须是simplify=False