How to change plot background color?
Set the plot background color in Matplotlib by altering the facecolor
attribute as shown:
To customize the plot's (axes) appearance, use ax.set_facecolor()
. And for the surrounding figure area, plt.gcf().set_facecolor()
serves the purpose.
Color it your way – Customize backgrounds
Targeted color changes with OO interface
Use the object-oriented interface (OOI) in Matplotlib
for precise tweaks like changing background colors:
Consistency across plots with rcParams
Want the same look for all your plots? rcParams
to the rescue! Set the color once, and forget about it:
Note: axisbg
is outdated, use ax.set_facecolor
or ax.patch.set_facecolor
instead.
Picking the right color
Fancy color names and palettes
Matplotlib
takes color selection to the next level: named colors, Tableau 'T10' categorical palette, and colors from the unique xkcd color survey.
Going grayscale
Keep it professional and minimalistic with grayscale:
Transparency and Hex in action
Experience the power of RGBA values and Hex codes:
Troubleshooting
No color changes in the plot? Make sure they happen before the plt.show()
call!
Was this article helpful?