'class matplotlib.patches.Ellipse for polar plot

Is there a possibility to add a ellipse in a polar plot? The matplotlib patches ellipse class neeeds (x,y,width,height), where (x,y) is the center and width and height the total length (diameter) of horizontal/vertical axis.

If I transform the polar cords to cartesian cords for the center it does not work.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse

fig=plt.figure()
ax=plt.subplot(111, polar=True)
x= 200*np.cos(np.pi)
y= 200*np.sin(np.pi)
ax.add_patch(Ellipse((x,y),100,100,fill=False))
plt.show()

so far



Solution 1:[1]

I am guessing that you did it by now but in case somebody wonder and wander around:

el = Ellipse((0.61 * np.pi, 0.8), 0.09, 0.08, color='black')
    ax.add_patch(el)

having the mouse hover the polar plot will give you you the information of 0.61?,0.8

Solution 2:[2]

What worked for me drawing a rectangle is the following:

1.- Get polar coordinates of rectangle:

rec_pts=ax.InvertedPolarTransform().transform(values=rectangle_points)

2.- Plot a line on the polar axis with such coordinates:

line,=ax.plot(rec_pts[:,0],rec_pts[:,1])

3.- Draw desired Patch using such line's path, already in polar coords:

from matplotlib.patches import PathPatch
ax.add_patch(PathPatch(line.get_path()))
line.remove()

In your case, in order to get your cartesian coordinates, a 0 step would be:

ellip_coords=Ellipse((x,y),100,100,fill=False).get_verts()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pierre
Solution 2 Pablo