Reputation: 71
I'm sure this is a basic question, but I am trying to make a plot of three ellipses from the semi-major axis (a), the semi-minor axis (b) and the angle that the ellipse is rotated (p).
I have a, b, and the rotation stored in three separate arrays a = [a1,a2,a3], b=[b1,b2,b3] and p=[p1,p2,p3].
I am new to matplotlib and I don't know how to pass these three parameters through to make three separate graphs of ellipses.
Here is my code so far:
ellipse_one = [Ellipse(xy= (0,0), width=a_ellipse_one, height=b_ellipse_one, angle = rotation_ellipse_one)
plt.gca().add_patch(ellipse_one)
ax.add_patch(ellipse_one)
plt.axis('scaled')
plt.show()
Upvotes: 0
Views: 491
Reputation: 1975
This creates 3 ellipses in the same figure:
for w, h, angle in zip(a, b, p):
ellipse = Ellipse(xy=(0,0), width=w, height=h, angle=angle)
ax.add_patch(ellipse)
plt.axis('scaled')
plt.show()
To put each ellipse in a separate subplot, do something like this:
fig, axes = plt.subplots(len(a), sharex=True, sharey=True)
for ax, w, h, angle in zip(axes, a, b, p):
ellipse = Ellipse(xy=(0,0), width=w, height=h, angle=angle)
ax.add_patch(ellipse)
plt.axis('auto')
plt.show()
Upvotes: 1