I am using seaborn for create plot according to this example.
import numpy as np
import pandas as pd
import seaborn as sns
sns.set(style="white")
rs = np.random.RandomState(5)
mean = [0, 0]
cov = [(1, .5), (.5, 1)]
x1, x2 = rs.multivariate_normal(mean, cov, 500).T
x1 = pd.Series(x1, name="$X_1$")
x2 = pd.Series(x2, name="$X_2$")
g = sns.jointplot(x1, x2, kind="kde", size=7, space=0)
However, when I change the last line of code to
g = sns.jointplot(x1, x2, kind="kde", size=7, space=0, xlim=(-5,5), ylim=(-5,5))
the background color does not change correctly:
How I can fix the background color so that it fills the whole plot?
Use the seaborn. set() Function to Change the Background Color of Seaborn Plots in Python. The set() function adds different elements and configures the aesthetics of the plot. There is no direct argument or method to change background color in seaborn.
You'll need to tell the underlying function (kdeplot
) to extend its KDE estimate farther out. This is accomplished through the cut
argument, which is a function of the KDE bandwidth. It defaults to 3, and there's no obvious way to tell exactly how you need to set it, but it shouldn't be that hard to play around and find values that work. When using jointplot
, you'll want to pass this in the joint_kws
dictionary so that it gets sent to the appropriate plotting function.
sns.jointplot(x1, x2, kind="kde", size=7, space=0,
joint_kws={"cut": 10},
xlim=(-5,5), ylim=(-5,5))
Voila:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With