Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set up the size of backgound colour plot to the size of axes in seaborn jointplot

Tags:

python

seaborn

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: enter image description here

How I can fix the background color so that it fills the whole plot?

like image 876
lalvarado Avatar asked Sep 19 '14 15:09

lalvarado


People also ask

How do I change the background color in Seaborn 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.


1 Answers

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:

enter image description here

like image 123
mwaskom Avatar answered Oct 12 '22 09:10

mwaskom