HOWTO · Matplotlib
How to Plot a Circle in Matplotlib
Draw a circle in Matplotlib with a Circle patch, its equation, or a scatter marker.
On this page
To draw a geometric circle in Matplotlib, use matplotlib.patches.Circle and add the patch to an Axes. You can also plot a circle from its equation or use a scatter marker for a quick circular symbol. A patch is usually the most direct choice when the circle needs a center and radius in data coordinates.
Draw a Circle with matplotlib.patches.Circle
matplotlib.patches.Circle creates a patch from a center (x, y) and radius. Add it to an Axes with add_patch; set an equal aspect ratio so one unit on the x-axis has the same display length as one unit on the y-axis.
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
fig, ax = plt.subplots()
ax.add_patch(Circle((2, 1), radius=0.75, fill=False, linewidth=2))
ax.set_aspect("equal", adjustable="box")
ax.set_xlim(0, 4)
ax.set_ylim(-1, 3)
ax.set_title("Circle patch")
plt.show()
Change the first argument to move the center and radius to resize the circle. Set fill=True (the default) to fill it, or use fill=False for an outline. Circle is an Artist, so it can also be attached with ax.add_artist(circle). If a plot already exists, plt.gcf().gca().add_artist(circle) adds it to the current figure’s current Axes; using an explicit Axes is clearer when a figure has multiple plots.
If you set axis limits manually, include the circle’s full extent: for center (cx, cy) and radius r, the x range must cover cx - r through cx + r, and the y range must cover cy - r through cy + r. Limits that stop inside those ranges hide part of a patch or an equation-based curve. Leave enough margin if you also want the outline to remain clear near the frame.
Draw a Circle from Its Equation
A parametric equation describes points around a circle. For center (cx, cy) and radius r, use x = cx + r cos(theta) and y = cy + r sin(theta). Sampling angles from zero through 2π traces the full curve.
import numpy as np
import matplotlib.pyplot as plt
center_x, center_y = 2, 1
radius = 0.75
theta = np.linspace(0, 2 * np.pi, 200)
x = center_x + radius * np.cos(theta)
y = center_y + radius * np.sin(theta)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_aspect("equal", adjustable="box")
ax.set_title("Circle from a parametric equation")
plt.show()
The center-radius equation (x - cx)² + (y - cy)² = r² can instead be drawn as a contour at level zero. Subtract r**2 from the left side, evaluate the result on a mesh grid, and draw the zero contour. Choose grid limits that include the full circle and keep equal axis scaling; otherwise the displayed curve can look stretched.
import numpy as np
import matplotlib.pyplot as plt
center_x, center_y = 2, 1
radius = 0.75
x = np.linspace(center_x - radius - 0.25, center_x + radius + 0.25, 100)
y = np.linspace(center_y - radius - 0.25, center_y + radius + 0.25, 100)
X, Y = np.meshgrid(x, y)
values = (X - center_x) ** 2 + (Y - center_y) ** 2 - radius ** 2
fig, ax = plt.subplots()
ax.contour(X, Y, values, levels=[0])
ax.set_aspect("equal", adjustable="box")
ax.set_title("Circle from the center-radius equation")
plt.show()
Draw a Circle with a Scatter Marker
scatter draws a marker at each supplied data point. Its s argument sets marker area in points squared, so it is useful for a circular symbol whose visual size stays tied to the display, rather than a geometric circle whose radius is measured in data coordinates.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter([2], [1], s=500, marker="o")
ax.set_xlim(0, 4)
ax.set_ylim(-1, 3)
ax.set_aspect("equal", adjustable="box")
ax.set_title("Circular scatter marker")
plt.show()
Increase or decrease s to change the marker’s displayed area. Use a Circle patch when the radius must correspond to distances on the plot’s axes; use a scatter marker when you want a consistent visual marker at a data point.
This display-sized behavior is useful for highlighting measured points, marking a center, or placing symbols on plots that readers may zoom. The marker stays tied to typographic points while the axes change scale, so its apparent size does not represent a fixed distance in the plotted data. Choose a patch or equation curve when the circle itself represents a radius that readers should compare with other data values.
Why a Circle Can Look Like an Ellipse
Every example above sets an equal aspect ratio with set_aspect("equal", adjustable="box"). Without that line, Matplotlib uses its automatic aspect ratio: the Axes fills its box, and because the box is wider than it is tall, one unit on the x-axis is drawn longer than one unit on the y-axis. The patch is still a circle in data coordinates, but on screen it looks like an ellipse. The example below uses the same center and radius as the first example and only omits the aspect-ratio line.
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
fig, ax = plt.subplots()
ax.add_patch(Circle((2, 1), radius=0.75, fill=False, linewidth=2))
ax.set_xlim(0, 4)
ax.set_ylim(-1, 3)
ax.set_title("Circle patch without an equal aspect ratio")
plt.show()
The fix is to add ax.set_aspect("equal", adjustable="box") before setting the limits, as in the earlier examples. Equation curves and contours distort in the same way: without an equal aspect ratio, every method in this article appears stretched. With adjustable="box", the Axes may shrink so both axes share one scale; that is expected behavior, not an error in the data.