Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Set facecolor in ax.legend() to choose a scatter plot legend’s background color:
leg = ax.legend(facecolor="lightyellow", edgecolor="0.3", framealpha=1)
This changes the legend frame, not the scatter markers. If the legend already exists, set the frame color with leg.get_frame().set_facecolor("lightyellow").
As an Amazon Associate I earn from qualifying purchases.
Set the legend background when creating it
Pass facecolor to Axes.legend when you create the legend. This example labels two scatter series and gives the legend an opaque white background with a gray border:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter(x_a, y_a, c="tab:blue", label="Group A")
ax.scatter(x_b, y_b, c="tab:orange", label="Group B")
ax.legend(facecolor="white", edgecolor="0.25", framealpha=1)
plt.show()
Replace x_a, y_a, x_b, and y_b with your data arrays. The Matplotlib Axes.legend API describes facecolor as the legend’s background color.
#1 Best Overall
Change the facecolor of a legend that already exists
Keep the legend object returned by ax.legend(), then update its frame:
leg = ax.legend()
leg.get_frame().set_facecolor("lightyellow")
This is useful when a legend was created elsewhere or its appearance is being adjusted later. Matplotlib’s legend gallery also demonstrates changing the frame with legend.get_frame().set_facecolor('C0').
Rank #2
Why the legend can match the axes background
By default, the legend facecolor comes from rcParams["legend.facecolor"], whose default is "inherit". Inheritance uses axes.facecolor, so the legend can appear to share the axes background. Set an explicit facecolor to override that behavior. See the Matplotlib configuration guide for the relevant defaults.
Control the frame and markers independently
The legend frame has separate settings for its background, border, and transparency:
facecolorsets the legend background.edgecolorsets the frame border color.framealphasets the background transparency.
These options do not recolor the scatter data or its legend markers. Set marker colors on the scatter calls themselves, or use the handles generated for mapped colors or sizes. Matplotlib’s collections API documents scatter legend elements; the scatter plot guide covers scatter plots. For legends with scatter markers, scatterpoints controls how many points appear in each entry.
Choose the right method
| Situation | Use |
|---|---|
| Creating the legend | ax.legend(facecolor="...") |
| Legend already exists | leg.get_frame().set_facecolor("...") |
The cited API reference identifies itself as Matplotlib 3.11.2. If you need behavior specific to another release, check the documentation for the version installed in your environment.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.




