seaborn —— 课后练✋
%matplotlib inline
import numpy as np
import pandas as pd
from scipy import stats, integrate
import matplotlib as mpl
from matplotlib import pyplot as plt
import seaborn as sns
练习1:鸢尾花花型尺寸分析
鸢尾花萼片(sepal)和花瓣(petal)的大小关系(散点图)
不同种类(species)鸢尾花萼片和花瓣的分布情况(箱图或者提琴图)
鸢尾花萼片和花瓣大小的联合分布情况(六角箱图或者核密度估计)
data = sns.load_dataset("iris")
data.head()
# 萼片长度,萼片宽度,花瓣长度,花瓣宽度,种类
sepal_length
sepal_width
petal_length
petal_width
species
0
5.1
3.5
1.4
0.2
setosa
1
4.9
3.0
1.4
0.2
setosa
2
4.7
3.2
1.3
0.2
setosa
3
4.6
3.1
1.5
0.2
setosa
4
5.0
3.6
1.4
0.2
setosa
data['sepal_size']=data['sepal_length']*data['sepal_width']
data['petal_size']=data['petal_length']*data['petal_width']
萼片与花瓣
sns.lmplot(x='sepal_size',y='petal_size',data=data)
不同种类 萼片与花瓣分布
g = sns.PairGrid(data,
x_vars=["species"],
y_vars=["sepal_size", "petal_size"],
aspect=2, size=4)
g.map(sns.violinplot, palette="pastel");
萼片与花瓣大小联合分布
# your code
sns.jointplot(x='sepal_length',y='petal_length',data=data,kind='kde')
/opt/ds/local/lib/python2.7/site-packages/numpy/ma/core.py:6385: MaskedArrayFutureWarning: In the future the default for ma.minimum.reduce will be axis=0, not the current None, to match np.minimum.reduce. Explici