在点周围画椭圆

Draw ellipses around points(在点周围画椭圆)
本文介绍了在点周围画椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用 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).

这篇关于在点周围画椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

build conda package from local python package(从本地 python 包构建 conda 包)
How can I see all packages that depend on a certain package with PIP?(如何使用 PIP 查看依赖于某个包的所有包?)
How to organize multiple python files into a single module without it behaving like a package?(如何将多个 python 文件组织到一个模块中而不像一个包一样?)
Check if requirements are up to date(检查要求是否是最新的)
How to upload new versions of project to PyPI with twine?(如何使用 twine 将新版本的项目上传到 PyPI?)
Why #egg=foo when pip-installing from git repo(为什么从 git repo 进行 pip 安装时 #egg=foo)