【问题标题】:Draw ellipse based on data with matplotlib使用matplotlib根据数据绘制椭圆
【发布时间】:2015-11-17 22:18:02
【问题描述】:

我试图在我的绘图上画一个椭圆,以表示一个集群。 下面的代码绘制了第一张图片。它在for循环中,但并不重要

native_f1 = [some values here]
native_f2 = [some values here]

ax = plt.subplot(2, 2, index)
ax.scatter(native_f1, native_f2, s=40)
axes = plt.gca()
axes.set_xlim([min(native_f1) - 800, max(native_f1) + 800])
axes.set_ylim([min(native_f2) - 800, max(native_f2) + 800])

现在我想获得类似的东西:

如何根据用于绘制这些图形的值绘制椭圆? 谢谢

【问题讨论】:

    标签: python matplotlib ellipse


    【解决方案1】:

    ellipse 的等式是 $\pm b \sqrt{1 - (x-x0)^2/a^2} + y0$,其中 (x0,y0) 是椭圆的中心。 (详情请参阅Draw ellipses around points)。

    您可以通过x2 = max(native_f1)x1 = min(native_f1)y2 = max(native_f2)y1 = min(native_f2) 找到椭圆的边缘。

    中心 (x0,y0) 将是 ( (x2+x1)/2, (y2+y1)/2 )。 y 方向 (b) 轴的比例将为(y2-y1)/2,x 方向 (a) 轴的比例将为(x2-x1)/2。根据需要使用软糖因素进行调整。

    您也可以使用matplotlib.patches.Ellipse

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 2013-11-26
      相关资源
      最近更新 更多