As a Python developer with over seven years of experience working extensively with Matplotlib, I’ve learned that small details can make a huge difference in your data visualizations. One such detail is customizing the legend’s face color in scatter plots.
This simple tweak can improve the readability and aesthetics of your plots, especially when presenting data to stakeholders or publishing reports.
In this guide, I’ll walk you through how to change the face color of the legend in Matplotlib scatter plots using Python. I’ll share multiple methods, including easy and more advanced approaches, so you can pick what fits your needs best.
Customize Legend Facecolor in Matplotlib Scatter Plots
If you’ve ever created scatter plots in Python using Matplotlib, you know legends help explain what each marker represents. But sometimes the default legend background color doesn’t blend well with your plot or presentation theme. Changing the legend’s face color improves visual clarity, making your charts look more professional.
For example, if you’re plotting sales data across different US regions with multiple categories, a well-styled legend can make it easier for your audience to quickly interpret which points belong to which region.
How to Change Legend Facecolor in Matplotlib: Step-by-Step
Let me share the easiest way to customize the legend face color in your scatter plots.
Method 1: Use legend() with facecolor Parameter
Matplotlib’s legend() method allows you to directly specify the background color of the legend box using the facecolor argument.
Here’s a complete example:
import matplotlib.pyplot as plt
# Sample data: Sales by region (USA)
regions = ['Northeast', 'Midwest', 'South', 'West']
sales = [250, 300, 450, 400]
growth = [5, 7, 3, 6]
# Scatter plot with different markers for each region
plt.scatter(regions, sales, s=100, c='blue', label='Sales')
plt.scatter(regions, growth, s=100, c='green', label='Growth')
# Customize legend with facecolor
legend = plt.legend(facecolor='lightyellow', edgecolor='black', title='Legend')
# Add title and labels
plt.title('Company Sales and Growth by Region (USA)')
plt.xlabel('Region')
plt.ylabel('Value')
plt.show()You can see the output in the screenshot below.

In this example, I set the legend’s facecolor to a soft yellow (lightyellow) and added a black edge for contrast. This instantly improves the legend’s visibility without overwhelming the plot.
Method 2: Use get_legend() and set_facecolor() for More Control
Sometimes you want to create the legend first and then modify its properties. This is useful in complex plots where you want to tweak legend styling after creation.
import matplotlib.pyplot as plt
# Data
regions = ['Northeast', 'Midwest', 'South', 'West']
sales = [250, 300, 450, 400]
growth = [5, 7, 3, 6]
# Scatter plot
plt.scatter(regions, sales, s=100, c='red', label='Sales')
plt.scatter(regions, growth, s=100, c='orange', label='Growth')
# Create legend
plt.legend(title='Legend')
# Modify legend facecolor after creation
legend = plt.gca().get_legend()
legend.get_frame().set_facecolor('lightblue')
legend.get_frame().set_edgecolor('navy')
# Titles and labels
plt.title('Company Sales and Growth by Region (USA)')
plt.xlabel('Region')
plt.ylabel('Value')
plt.show()You can see the output in the screenshot below.

This approach gives you granular control over the legend’s frame. You can adjust the facecolor, edgecolor, and even transparency by using set_alpha() if desired.
Method 3: Make Legend Background Transparent
In some cases, you may want the legend background to be transparent so it doesn’t obscure any part of your scatter plot. Here’s how you can do that:
import matplotlib.pyplot as plt
# Data
regions = ['Northeast', 'Midwest', 'South', 'West']
sales = [250, 300, 450, 400]
growth = [5, 7, 3, 6]
# Scatter plot
plt.scatter(regions, sales, s=100, c='purple', label='Sales')
plt.scatter(regions, growth, s=100, c='cyan', label='Growth')
# Create legend with transparent background
legend = plt.legend(title='Legend')
legend.get_frame().set_alpha(0.3) # 30% transparency
# Titles and labels
plt.title('Company Sales and Growth by Region (USA)')
plt.xlabel('Region')
plt.ylabel('Value')
plt.show()You can see the output in the screenshot below.

This method sets the legend box’s alpha transparency to 0.3, allowing the plot elements behind the legend to be partially visible. It’s a neat way to keep your visualization uncluttered.
Tips from My Experience for Better Legend Styling in Python Matplotlib
- Choose contrasting colors: Ensure your legend facecolor contrasts well with both the plot background and the marker colors to maintain readability.
- Use subtle colors: Avoid overly bright or saturated colors for the legend background; softer shades tend to look more professional.
- Add edges to legends: Adding an edge color helps the legend stand out distinctly from the plot.
- Consider transparency: Transparency can help integrate the legend smoothly without covering important plot details.
- Consistent styling: If you have multiple plots in a report or dashboard, keep legend facecolors consistent for a cohesive look.
Customizing the legend facecolor in Matplotlib scatter plots is a simple yet effective way to enhance your Python data visualizations. Whether you prefer directly setting the facecolor during legend creation or tweaking it afterward, these methods give you the flexibility to match your plot’s style and purpose.
From my years of working on data visualization projects involving US regional sales data, I can confidently say that these small styling changes make a big difference in how your audience interprets your charts.
Try these techniques in your next Python Matplotlib scatter plot and see how a well-styled legend improves your presentation’s professionalism and clarity.
You may read:
- Create Multiple Bar Charts in Pandas Using Python Matplotlib
- Matplotlib Grouped Bar Charts in Python
- Overlay Two Bar Charts in Matplotlib with Python
- Add Multiple Bar Chart Labels in Matplotlib with 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.