seaborn example¶
Imports
[1]:
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
Define style
seaborn.set is an alias for seaborn.set_theme, which can be used to define different styles, palettes, fonts and colours, for example:
[2]:
sns.set(style="white", color_codes=True)
Creating a bivariate random data set
For this we use numpy.random.RandomState.multivariate_normal from numpy.random.RandomState, where a seed of
9
,0
as mean values and 100 samples result in a not quite symmetrical covariance matrix:
[3]:
rs = np.random.RandomState(9)
mean = [0, 0]
cov = [(1, 0), (0, 2)]
x, y = rs.multivariate_normal(mean, cov, 100).T
JointGrid
for bivariate plotsBivariate plots can be generated with seaborn.JointGrid. If both functions pass different keyword arguments, JointGrid.plot_joint() and JointGrid.plot_marginals() must be used:
[4]:
grid = sns.JointGrid(x=x, y=y, space=0, height=6, ratio=10)
grid.plot_joint(plt.scatter, color="g")
grid.plot_marginals(sns.rugplot, height=0.2, color="g")
[4]:
<seaborn.axisgrid.JointGrid at 0x154b964d0>
