Setting plot background colour in Seaborn

seaborn.set takes an rc argument that accepts a dictionary of valid matplotlib rcparams. So we need to set two things: the axes.facecolor, which is the color of the area where the data are drawn, and the figure.facecolor, which is the everything a part of the figure outside of the axes object.

(edited with advice from @mwaskom)

So if you do:

%matplotlib inline
import matplotlib.pyplot as plt
import seaborn
seaborn.set(rc={'axes.facecolor':'cornflowerblue', 'figure.facecolor':'cornflowerblue'})

fig, ax = plt.subplots()

You get:

enter image description here

And that'll work with your FacetGrid as well.


I am not familiar with seaborn but the following appears to let you change the background by setting the axes background. It can set any of the ax.set_* elements.

import seaborn as sns
import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt

m=pd.DataFrame({'x':['1','1','2','2','13','13'],
                'y':np.random.randn(6)})

facet = sns.factorplot('x','y',data=m)

facet.set(axis_bgcolor='k')

plt.show()

Another way is to set the theme:

seaborn.set_theme(style='white')