我正在尝试使用 matplotlib 在图表上的一组点周围绘制椭圆.我想得到这样的东西:
一个组的数据集(例如红色的)可能如下所示:
[[-23.88315146 -3.26328266] #第一点[-25.94906669 -1.47440904] # 第二点[-26.52423229 -4.84947907]] # 第三点
我可以很容易地在图表上绘制点,但是我在绘制椭圆时遇到了问题.
椭圆的直径为2 * 标准差
,其中心坐标为(x_mean, y_mean)
.一个椭圆的宽度等于 x 标准差 * 2
.它的高度等于 y 标准差 * 2
.
但是,我不知道如何计算椭圆的角度(您可以在图片上看到椭圆不是完全垂直的).
你知道怎么做吗?
注意:这个问题是 LDA 问题(线性判别分析)的简化.我正在尝试将问题简化为最基本的表达方式.
这是一个经过充分研究的问题.首先取点集的).
I'm trying to draw ellipses around points of a group on a graph, with matplotlib. I would like to obtain something like this:
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.
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).
Charles F. Van Loan. "Using the Ellipse to Fit and Enclose Data Points." (PDF download).
这篇关于在点周围画椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!