Here is an example of a seaborn bivariate KDE plot from the Iris dataset. Code:
from sklearn import datasets
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Setting up the Data Frame
iris = datasets.load_iris()
iris_df = pd.DataFrame(iris.data, columns=['Sepal_Length',
'Sepal_Width', 'Patal_Length', 'Petal_Width'])
# Adding the Target column to the df which indicates the species
iris_df['Target'] = iris.target
# Iris Setosa corresponds to 0 value in Target column
iris_setosa = iris_df.query("Target==0")
# Plotting the KDE Plot
sns.kdeplot(iris_setosa['Sepal_Length'], iris_setosa['Sepal_Width'], shade=True, Label='Iris_Setosa',cbar=True)
plt.show()
I wish to extract the data from the plot and store it. I am able to extract the polygons for each contour line. However, I can't seem to find a way to extract the z / threshold values for each contour line, i.e. the values along the right-hand side of the plot which correspond to a certain colour for the contour lines.
Can anyone help me with this?