survived pclass sex age sibsp parch fare embarked class \
0 0 3 male 22.0 1 0 7.2500 S Third
1 1 1 female 38.0 1 0 71.2833 C First
2 1 3 female 26.0 0 0 7.9250 S Third
3 1 1 female 35.0 1 0 53.1000 S First
4 0 3 male 35.0 0 0 8.0500 S Third
who adult_male deck embark_town alive alone
0 man True NaN Southampton no False
1 woman False C Cherbourg yes False
2 woman False NaN Southampton yes True
3 woman False C Southampton yes False
4 man True NaN Southampton no True
<matplotlib.axes._subplots.AxesSubplot at 0x1a1f4e4210>
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/categorical.py:3669: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
warnings.warn(msg)
<seaborn.axisgrid.FacetGrid at 0x1a200f9210>
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/categorical.py:3669: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
warnings.warn(msg)
<seaborn.axisgrid.FacetGrid at 0x1a203d0c10>
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/categorical.py:3669: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
warnings.warn(msg)
<seaborn.axisgrid.FacetGrid at 0x1a1f5003d0>
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/categorical.py:3669: UserWarning: The `factorplot` function has been renamed to `catplot`. The original name will be removed in a future release. Please update your code. Note that the default `kind` in `factorplot` (`'point'`) has changed `'strip'` in `catplot`.
warnings.warn(msg)
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/categorical.py:3675: UserWarning: The `size` parameter has been renamed to `height`; please update your code.
warnings.warn(msg, UserWarning)
<seaborn.axisgrid.FacetGrid at 0x1a1e45a550>
g = sns.FacetGrid(tips,col="time")
g.map(plt.hist,"tip")
<seaborn.axisgrid.FacetGrid at 0x1a211dd8d0>
g = sns.FacetGrid(tips, col="sex", hue="smoker")
g.map(plt.scatter,"total_bill","tip",alpha=0.7)
g.add_legend()# 添加图例
<seaborn.axisgrid.FacetGrid at 0x1a21361b50>
g = sns.FacetGrid(tips, row="smoker",col="time", margin_titles=True)
g.map(sns.regplot,"size","total_bill",color="0.3",
fit_reg=True,# fit_reg是否显示回归线
x_jitter=0.1)# jitter浮动
<seaborn.axisgrid.FacetGrid at 0x1a21ded350>
g = sns.FacetGrid(tips,col="day",size=4,aspect=0.5)
g.map(sns.barplot,"sex","total_bill")
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/axisgrid.py:243: UserWarning: The `size` parameter has been renamed to `height`; please update your code.
warnings.warn(msg, UserWarning)
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/axisgrid.py:728: UserWarning: Using the barplot function without specifying `order` is likely to produce an incorrect plot.
warnings.warn(warning)
<seaborn.axisgrid.FacetGrid at 0x1a224f5850>
from pandas import Categorical
ordered_days = tips.day.value_counts().index
print(order_days)# ordered_days = Categorical(["Thur","Fri","Sat","Sun"])
g = sns.FacetGrid(tips,row="day",row_order=ordered_days,
size=1.7,aspect=4)# size被替换成height
g.map(sns.boxplot,"total_bill")
CategoricalIndex(['Sat', 'Sun', 'Thur', 'Fri'], categories=['Thur', 'Fri', 'Sat', 'Sun'], ordered=False, dtype='category')
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/axisgrid.py:243: UserWarning: The `size` parameter has been renamed to `height`; please update your code.
warnings.warn(msg, UserWarning)
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/axisgrid.py:728: UserWarning: Using the boxplot function without specifying `order` is likely to produce an incorrect plot.
warnings.warn(warning)
<seaborn.axisgrid.FacetGrid at 0x1a240e54d0>
pal =dict(Lunch="seagreen",Dinner="gray")
g = sns.FacetGrid(tips,hue="time",palette=pal,height=5)
g.map(plt.scatter,"total_bill","tip", s=50,alpha=0.7,linewidth=0.5,edgecolor="white")
g.add_legend()
<seaborn.axisgrid.FacetGrid at 0x1a24220550>
g = sns.FacetGrid(tips,hue="sex",palette="Set1",size=5,
hue_kws={"marker":["^","v"]})
g.map(plt.scatter,"total_bill","tip", s=100,alpha=0.7,
linewidth=0.5,edgecolor="white")
g.add_legend()
<seaborn.axisgrid.FacetGrid at 0x1a241e1a90>
with sns.axes_style("white"):
g = sns.FacetGrid(tips, row="sex", col="smoker", margin_titles=True,
size=2.5)
g.map(plt.scatter,"total_bill","tip",color="#334488",edgecolor="white",lw=0.5)
g.set_axis_labels("Total bill(US Dollars)","Tip")
g.set(xticks=[10,30,50], yticks=[2,6,10])#x,y轴刻度范围
g.fig.subplots_adjust(wspace=0.2, hspace=0.2) # 设置子图间隔
/Users/susu/opt/anaconda3/envs/data_analysis/lib/python3.7/site-packages/seaborn/axisgrid.py:243: UserWarning: The `size` parameter has been renamed to `height`; please update your code.
warnings.warn(msg, UserWarning)
iris = sns.load_dataset("iris")
g = sns.PairGrid(iris)
g.map(plt.scatter)
<seaborn.axisgrid.PairGrid at 0x1a24841050>
g = sns.PairGrid(iris)
g.map_diag(plt.hist)# 指定对角线的图
g.map_offdiag(plt.scatter)# 指定非对角线的图
<seaborn.axisgrid.PairGrid at 0x1a24ee9810>
g = sns.PairGrid(iris,hue="species")
g.map_diag(plt.hist)# 指定对角线的图
g.map_offdiag(plt.scatter)# 指定非对角线的图
g.add_legend()
<seaborn.axisgrid.PairGrid at 0x1a259de0d0>
g = sns.PairGrid(iris,hue="species",vars=["sepal_length","sepal_width"])# vars:指定需要绘制的特征
g.map(plt.scatter)
<seaborn.axisgrid.PairGrid at 0x1a26bb7590>
g = sns.PairGrid(tips,hue="size",palette="GnBu_d")
g.map(plt.scatter,s=50,edgecolor="white")
g.add_legend()
<seaborn.axisgrid.PairGrid at 0x1a26da8910>
# 7.热度图--->heatmap()# 常用于特征与特征的相关程度%matplotlib inline
import numpy as np
import pandas as pd
import seaborn as sns
np.random.seed(0)
sns.set()
数据集下载链接:import seaborn as snsimport matplotlib as mplimport matplotlib.pyplot as pltimport numpy as npimport pandas as pd%matplotlib inlinedef sinplot(flip=1): x = np.linspace(0,14,100)...