As a Python developer with over eight years of experience using Matplotlib, I’ve often found myself needing to enhance the visual appeal and clarity of my plots. One of the most useful functions I frequently use is fill_between. It helps me highlight regions between two lines, making data comparisons easier and more intuitive.
However, customizing the look of these filled areas, especially hatch patterns and their colors, can be a bit tricky. In this article, I’ll share my firsthand experience on how to control hatch color and facecolor in Matplotlib’s fill_between. This guide will walk you through multiple methods, complete with Python code examples, so you can create more professional and insightful visualizations.
Matplotlib fill_between in Python
Before getting into customization, let me quickly recap what fill_between does. This function fills the area between two curves or lines on a plot. It’s commonly used in financial charts, weather data visualization, or any scenario where you want to emphasize the difference between datasets.
By default, fill_between fills the area with a solid color, but you can add hatch patterns (like stripes, dots, or crosses) for better distinction, especially useful when printing in black and white or for accessibility reasons.
Customize Hatch Color in Matplotlib fill_between
Matplotlib allows you to add hatching patterns to the filled area, but controlling the color of these hatches requires some extra steps. Let me show you two effective methods to customize hatch colors.
Method 1: Use fill_between with Patch Properties and Edge Color
The hatch pattern in Matplotlib is actually drawn as the edge of the polygon patch created by fill_between. By default, the hatch color is the same as the edge color of the patch. We can exploit this to change the hatch color by setting the edgecolor parameter.
Here’s a Python example where I fill the area between two sine waves and set the hatch color to red, while the facecolor stays blue:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 500)
y1 = np.sin(x)
y2 = np.sin(x) + 0.5
plt.plot(x, y1, label='y1 = sin(x)')
plt.plot(x, y2, label='y2 = sin(x) + 0.5')
# Fill between with hatch pattern and custom hatch color (edgecolor)
plt.fill_between(x, y1, y2, facecolor='blue', hatch='///', edgecolor='red', alpha=0.3)
plt.legend()
plt.title('fill_between with Custom Hatch Color')
plt.show()I executed the above example code and added the screenshot below.

In this example, the hatch lines appear in red because edgecolor=’red’ controls the hatch color. The facecolor remains blue and semi-transparent due to alpha=0.3.
Method 2: Access the Patch Object for More Control
Sometimes, you want to control the hatch color separately from the edge color of the patch outline. Matplotlib doesn’t provide a direct parameter for hatch color in fill_between, but you can manipulate the patch objects after creation.
Here’s how I do it:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 500)
y1 = np.cos(x)
y2 = np.cos(x) + 0.5
plt.plot(x, y1, label='y1 = cos(x)')
plt.plot(x, y2, label='y2 = cos(x) + 0.5')
# Create the fill_between object
filled = plt.fill_between(x, y1, y2, facecolor='yellow', hatch='xxx', edgecolor='black', alpha=0.5)
# Access the Patch object and change hatch color by modifying edge color
for patch in filled.get_paths():
pass # This is a placeholder; hatch color controlled by edgecolor
# Alternatively, change edgecolor after creation
filled.set_edgecolor('green')
plt.legend()
plt.title('fill_between with Hatch Color Modified Post Creation')
plt.show()I executed the above example code and added the screenshot below.

In practice, the hatch color is linked to the edge color of the patch, so updating the edge color after creation changes the hatch color. This method gives you the flexibility to adjust colors dynamically.
Customize Facecolor in Matplotlib fill_between
The facecolor controls the fill color inside the hatched or solid area. You can customize it directly in fill_between or by modifying the patch object. Here are two easy methods.
Method 1: Directly Setting Facecolor in fill_between
The simplest way to set the fill color is by passing the facecolor parameter to fill_between. Here’s an example where I fill the area between two datasets with a semi-transparent green:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 500)
y1 = np.sin(x)
y2 = np.sin(x) + 1
plt.plot(x, y1, label='sin(x)')
plt.plot(x, y2, label='sin(x) + 1')
plt.fill_between(x, y1, y2, facecolor='green', alpha=0.4)
plt.legend()
plt.title('fill_between with Custom Facecolor')
plt.show()I executed the above example code and added the screenshot below.

This method is simple and works perfectly when you want a solid fill color with optional transparency.
Method 2: Change Facecolor After Creation
If you want to update the fill color dynamically, you can modify the patch object returned by fill_between. Here’s how I do it:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 500)
y1 = np.cos(x)
y2 = np.cos(x) + 1
plt.plot(x, y1, label='cos(x)')
plt.plot(x, y2, label='cos(x) + 1')
filled_area = plt.fill_between(x, y1, y2, facecolor='orange', alpha=0.5)
# Update facecolor after creation
filled_area.set_facecolor('purple')
plt.legend()
plt.title('fill_between with Facecolor Changed Post Creation')
plt.show()I executed the above example code and added the screenshot below.

This approach is useful when you want to create an interactive plot or update colors based on user input or data changes.
Conclusion
Customizing hatch color and facecolor in Matplotlib’s fill_between function can elevate the clarity and aesthetics of your Python visualizations. From my experience, setting the hatch color via the patch’s edge color is the most reliable approach, while facecolor customization is easy and flexible.
Whether you’re visualizing stock price ranges, climate data, or any time series, these techniques help you communicate your data story more effectively. Try combining hatch patterns with distinct colors and transparency to make your plots stand out, especially when presenting to diverse audiences or printing in grayscale.
If you want to explore more about Matplotlib styling, keep experimenting with patch properties and layering multiple fills. The power of Python’s Matplotlib lies in its flexibility, and mastering these small details will make your charts truly professional.
Related Python Guides you may like:
- Matplotlib tight_layout wspace and hspace in Python
- Matplotlib Tight_Layout for Python Subplots
- How to Use tight_layout and bbox_inches in Matplotlib
- Matplotlib Scatter Plots with Tight_Layout in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.