【问题标题】:Merging edges from overlapping ellipses in matplotlib从matplotlib中的重叠椭圆合并边缘
【发布时间】:2012-09-24 10:00:19
【问题描述】:

我需要绘制两个重叠的椭圆,当前代码将第二个椭圆的边缘放在第一个椭圆的顶部。代码如下:

from matplotlib.pyplot import figure, show
from matplotlib import patches
fig = figure()
ax = fig.add_subplot(111)
ell = patches.Ellipse((0.15, 0.7), .3, .1, angle = 25, facecolor = 'white', edgecolor = 'gray', linewidth = 2, transform=ax.transAxes)
ax.add_artist(ell)
ell = patches.Ellipse((0.30, 0.7), .3, .1, angle = -25, facecolor = 'white', edgecolor = 'gray', linewidth = 2, transform=ax.transAxes)
ax.add_artist(ell)
show()

这会产生一个类似于How to join overlapping circles? 的第一个数字(我不能在这里发布我自己的数字),而我想要第二个数字。

matplotlib 中有解决这个问题的方法吗?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    是的。但是您需要使用http://matplotlib.org/1.1.1/api/artist_api.html?highlight=arc#matplotlib.patches.Arc,因为Ellipse 没有theta1theta2 所需的角度参数。

    至于实际计算这些角度,椭圆的封闭形式解决方案可能比参考问题中给出的圆方程更复杂。如果您无法找到几何解,您可能不得不求助于数值近似来找到它们:编写一个距离函数 f(ta, tb),计算椭圆 A 上的点 ta 和椭圆 B 上的点 tb 之间的距离,然后搜索两个局部最小值 f(ta1, tb1) 和 f(ta2, tb2)。

    【讨论】:

    • 谢谢!我通过反复试验确定了角度,因为(希望)这是我拥有的唯一重叠椭圆的情况。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    相关资源
    最近更新 更多