There are a lot of different kinds of patches available, beyond just the simple circle. They are as follows:
- The circle, in which you can set the center and the radius.
- An arc, which is an elliptical arc, that takes a section of an ellipse that you specify using the width and the height. We can also change the angle that that ellipse is placed at and then, using a pair of angles, theta 1 and theta 2, we set how much of that ellipse is filled.
- A wedge, wherein we get an additional argument, called the width, which explains what fraction of that circle will be shown.
- An arrow, which specifies the position of the tail using the x and y coordinates and where that arrow will point using dx and dy. So, these will point in a vector away from the tail.
- There is also a filled ellipse, which includes width, height, and angle.
- A filled rectangle.
- An arbitrary polygon where we set the center, the number of vertices, the orientation, and the radius.
We will take a look at all of the patches:
# Different kinds of simple patches
circle = mpl.patches.Circle(xy=(2,-2), radius=1)
arc = mpl.patches.Arc(xy=(1,2), width=1, height=3, angle=0, theta1=90, theta2=270)
wedge = mpl.patches.Wedge(center=(2,2), r=1, theta1=-180, theta2=100, width=0.5)
arrow = mpl.patches.Arrow(x=4,y=-3, dx=2, dy=2)
ellipse = mpl.patches.Ellipse(xy=(5,2), width=1, height=3, angle=60)
rect = mpl.patches.Rectangle(xy=(7,-2), width=2, height=2, angle=-30)
poly = mpl.patches.RegularPolygon(xy=(8,2), numVertices=3, orientation=45, radius=1)
plt.plot(nums, 10/3.*np.sin(nums))
plt.gca().add_patch(circle)
plt.gca().add_patch(arc)
plt.gca().add_patch(wedge)
plt.gca().add_patch(arrow)
plt.gca().add_patch(ellipse)
plt.gca().add_patch(rect)
plt.gca().add_patch(poly)
In the following output, we have a circle, an arc, a wedge that is partially filled in, an ellipse, an arrow, a polygon, and a rectangle:
Now, you can probably already guess from this that a circle is more or less a special case of an ellipse, and a rectangle is more or less a special case of polygons. So, you can, in many cases, only get away with using a ellipse and polygon instead of a circle and rectangle, but there are a few cases where it makes sense to use the more explicit way of doing things.