Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
918 views
in Technique[技术] by (71.8m points)

python - Draw ellipses around points

I'm trying to draw ellipses around points of a group on a graph, with matplotlib. I would like to obtain something like this:

enter image description here

A dataset for a group (the red one for example) could look like this:

[[-23.88315146  -3.26328266]  # first point
 [-25.94906669  -1.47440904]  # second point
 [-26.52423229  -4.84947907]]  # third point

I can easily draw the points on a graph, but I encounter problems to draw the ellipses.

The ellipses have diameters of 2 * standard deviation, and its center has the coordinates (x_mean, y_mean). The width of one ellipse equals the x standard deviation * 2. Its height equals the y standard deviation * 2.

However, I don't know how to calculate the angle of the ellipses (you can see on the picture the ellipses are not perfectly vertical).

Do you have an idea about how to do that ?

Note: This question is a simplification of LDA problem (Linear Discriminant Analysis). I'm trying to simplify the problem to its most basic expression.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a well-studied problem. First take the convex hull of the set of points you wish to enclose. Then perform computations as described in the literature. I provide two sources below.

"Smallest Enclosing Ellipses--An Exact and Generic Implementation in C++" (abstract link).


          Ellipse

Charles F. Van Loan. "Using the Ellipse to Fit and Enclose Data Points." (PDF download).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...