鸢尾花数据集
# Visual Python: Data Analysis > File
vp_df = pd.read_csv('https://raw.githubusercontent.com/visualpython/visualpython/main/visualpython/data/sample_csv/iris.csv')
vp_df
import seaborn as sns
g = sns.pairplot(vp_df)
g.fig.set_size_inches(12,12)
#figure大小
sns.set(style='whitegrid',font_scale=3)
#文本大小
对角线4张图是变量自身的分布直方图;
非对角线的 12 张就是某个变量和另一个变量的关系
g = sns.pairplot(vp_df,
hue='variety'#按照三种花分类
)
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=3)
g = sns.pairplot(vp_df,
hue='variety',
palette='Greens',#Matplotlib颜色
)
#sns.set(style='whitegrid')
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
g = sns.pairplot(vp_df,
hue='variety',
palette=['green','yellow','blue'],#Matplotlib颜色
)
sns.set(style='whitegrid')
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
g = sns.pairplot(vp_df,
hue='variety',
vars=['sepal_length','sepal_width']
)
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=3)
g = sns.pairplot(vp_df,
hue='variety',
x_vars=['sepal_length','sepal_width'],
y_vars=['petal_length','petal_width']
)
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=3)
g = sns.pairplot(vp_df,
hue='variety',
palette=['green','yellow','blue'],#Matplotlib颜色
kind='reg'#前面的是 scatter(默认)
)
#sns.set(style='whitegrid')
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
hist/kde/None
g = sns.pairplot(vp_df,
hue='variety',
palette=['green','yellow','blue'],#Matplotlib颜色
diag_kind='hist'
)
#sns.set(style='whitegrid')
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
g = sns.pairplot(vp_df,
hue='variety',
palette=['green','yellow','blue'],#Matplotlib颜色
corner=True
)
#sns.set(style='whitegrid')
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
非对角线点的款式
款式见: ,pairmatplotlib 笔记:marker 款式_UQI-LIUWJ的博客-CSDN博客
g = sns.pairplot(vp_df,
hue='variety',
palette=['green','yellow','blue'],#Matplotlib颜色
markers=['o','P','*']
)
#sns.set(style='whitegrid')
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
g = sns.PairGrid(vp_df,
hue='variety',
palette='husl',)
g = g.map(plt.scatter)#map每个子图绘制一样类型的图
g = g.add_legend()
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
g = sns.PairGrid(vp_df,
hue='variety',
palette='husl',)
g=g.map_diag(plt.hist)
#对角线绘制直方图
g = g.map_offdiag(plt.scatter)
#非对角线绘制散点图
g = g.add_legend()
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)
g = sns.PairGrid(vp_df,
hue='variety',
palette='husl',)
g=g.map_upper(plt.scatter)
#对角线上方绘制散点图
g = g.map_diag(sns.kdeplot)
#对角线绘制核密度图
g=g.map_lower(sns.kdeplot)
#对角线下方绘制核密度图
g = g.add_legend()
g.fig.set_size_inches(12,12)
sns.set(style='whitegrid',font_scale=1.5)