0

I need to draw two overlapping ellipses and the current code puts the edges of the second ellipse atop the first ellipse. Here is the code:

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()

This produces a figure like the first figure at How to join overlapping circles? (I can't post my own figures here) while I want something like the second figure.

Is there a solution for this problem in matplotlib?

Community
  • 1
  • 1
oschoudhury
  • 1,086
  • 12
  • 17

1 Answers1

0

Yes. But you'll need to use http://matplotlib.org/1.1.1/api/artist_api.html?highlight=arc#matplotlib.patches.Arc, because Ellipse does not have the required angle arguments theta1 and theta2.

As for actually calculating those angles, a closed-form solution for ellipses is likely to be significantly more involved than the equations given in the referenced question for circles. If a geometric solution eludes you, you may have to resort to numerical approximation to find them: write a distance function f(ta, tb) that computes a distance between point ta on ellipse A and point tb on ellipse B, then search for the two local minima f(ta1, tb1) and f(ta2, tb2).

Dave
  • 3,834
  • 2
  • 29
  • 44
  • Thanks! I determined the angles by trial and error since this is (hopefully) the only case with overlapping ellipses which I have. – oschoudhury Sep 24 '12 at 14:26