Adjust the size of the color plot of the back to the size of the axes in the marine joint

I use seaborn to create a 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)) 

background color does not change correctly: enter image description here

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

+5
source share
2 answers

You will need to specify a base function ( kdeplot ) to extend its KDE evaluation further. This is achieved using the cut argument, which is a function of the KDE bandwidth. By default, it is 3, and there is no obvious way to tell exactly how you need to install it, but it is not so difficult to play and find values ​​that work. When using jointplot you want to pass this in the joint_kws dictionary joint_kws that it is sent to the corresponding joint_kws 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

+5
source

It is very close, but I can not exactly match the color. If you find the colourmap in the cm module ("cool"?), You can find the exact color.

 ax = plt.gcf().axes[0] ax.set_axis_bgcolor((.93,.93,1)) 

If you do this interactively, you will need plt.draw () to have a new color show.

0
source

Source: https://habr.com/ru/post/1202982/


All Articles