[SciPy-user] KDE question
Zachary Pincus
zpincus at stanford.edu
Sat Nov 10 07:14:39 EST 2007
>> I'm using scipy.stats.gaussian_kde to estimate the a probability
>> density based on some scattered 2D samples. What I would like to do
>> eventually is plot a line that surrounds (say) 90% of the probability
>> density.
>
> If its only plotting you are interested in, matplotlib can do all the
> dirty work for you, using the "contour" command:
>
> http://matplotlib.sourceforge.net/screenshots/pcolor_demo.py
> which yields:
> http://matplotlib.sourceforge.net/screenshots/pcolor_demo_large.png
In this case, the trick is to figure out *which* contour level to
plot -- that is, at what density level and above is 90% (say) of the
total density contained. Robert's example shows how to figure that
out, and pretty cleverly. I wouldn't have thought of wrapping it all
up with brentq.
But gosh, do those matplotlib contours look nice. I've been using
Gnuplot/Gnuplot.py for a long time, but it might be time to make a
switch.
Thanks,
Zach
More information about the SciPy-User
mailing list