Plot Ellipse with matplotlib.pyplot (Python)


Sorry if this is a stupid question, but is there an easy way to plot an ellipse with matplotlib.pyplot in Python? I was hoping there would be something similar to matplotlib.pyplot.arrow, but I can't find anything.

Is the only way to do it using matplotlib.patches with draw_artist or something similar? I would hope that there is a simpler method, but the documentation doesn't offer much help.

Thanks for any advice!

6/8/2012 3:47:18 PM

Accepted Answer

Have you seen the matplotlib ellipse demo? Here they use matplotlib.patches.Ellipse.

6/8/2012 3:55:24 PM

The matplotlib ellipse demo is nice. But I could not implement it in my code without a for loop. I was getting an axes figure error. Here is what I did instead, where of course the xy center are my own coordinates with respective width and height based on the image over which I plotted the ellipse.

from matplotlib.patches import Ellipse

ax = plt.gca()

ellipse = Ellipse(xy=(157.18, 68.4705), width=0.036, height=0.012, 
                        edgecolor='r', fc='None', lw=2)

This code is based partially on the very first code box on this page. See Chris's response above for a link to matplotlib.patches.Ellipse.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow