I am using gaussian_kde to generate 2-dimensional density estimates. Is there a way that I can calculate the level curves of this PDF with the property that a fixed amount of probability mass lies above a given height?
For example, I would like to determine the value z_0 for which the volume of the PDF below the surface z = z_0 is equal to, say, 0.5. Simple-minded attempts to solve this with root or with fsolve do not generally converge.
I've tried forming an array of z-values from evaluating the kde at a mesh grid of values which cover the bulk of the space, and then using root and/or fsolve to find the root of the function that takes a value z_0 and returns the difference between the sum of the z-values which exceed z_0 and the desired probability p. Even though this function is smooth and monotonic, root and fsolve do not consistently converge on the unique solution.