I would like to draw a contour plot of a Kernel Density Estimation, where the KDE is integrated within each of the contour plot filled areas.
As an example, imagine I calculate the KDE of 2D data:
data = np.random.multivariate_normal((0, 0), [[1, 1], [2, 0.7]], 100)
x = data[:, 0]
y = data[:, 1]
xmin, xmax = min(x), max(x)
ymin, ymax = min(y), max(y)
xx, yy = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([xx.ravel(), yy.ravel()])
values = np.vstack([x, y])
kernel = st.gaussian_kde(values)
f = np.reshape(kernel(positions).T, xx.shape)
I know how to draw the contourplot of the KDE.
fig = plt.figure()
ax = fig.gca()
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
cfset = ax.contourf(xx, yy, f, cmap='Blues')
cset = ax.contour(xx, yy, f, colors='k')
plt.show()
However, this contourplot shows what is the probability density within each of the filled areas. Instead, I would like the plot to indicate the total probability to fall within each of the filled areas.