Python:Matplotlib .fill()
Published Oct 31, 2025
Contribute to Docs
The .fill() function in Matplotlib fills the area enclosed by specified x and y coordinates with color. It’s often used to highlight or emphasize regions defined by one or more polygons on a plot.
Syntax
matplotlib.pyplot.fill(*args, data=None, **kwargs)
Parameters:
*args: One or more pairs of x and y coordinates defining the polygons to fill.data: An object (like a DataFrame or dict) that provides named variables forxandy.**kwargs: Additional keyword arguments controlling the fill style, such as:colororfacecolor: Fill color.edgecolor: Color of the polygon edge.linewidth: Width of polygon edges.alpha: Transparency level (0.0 to 1.0).- Any other valid
Polygonproperties.
Return value:
Returns a list of matplotlib.patches.Polygon objects representing the filled regions.
Example 1: Filling a Rectangle Shape
This example fills the area enclosed by a rectangle:
import matplotlib.pyplot as pltx = [0, 3, 3, 0]y = [0, 0, 3, 3]plt.fill(x, y, color='green', alpha=0.75)plt.title('Filled Rectangle')plt.show()
The output of this code is:

Example 2: Filling Custom Polygon Shapes
This example fills two different polygons using custom edge and fill colors:
import matplotlib.pyplot as plt# Polygon 1a = [0, 1, 2, 1]b = [0, 2, 0, -2]plt.fill(a, b, color='skyblue', edgecolor='red', linewidth=2)# Polygon 2m = [0, 0, 3, 3]n = [0, 3, 0, 3]plt.fill(m, n, color='pink', alpha=0.6)plt.title('Custom Filled Polygons')plt.show()
The output of this code is:

Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Matplotlib on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours