首页 > 其他分享 >[seaborn] seaborn学习笔记4 核密度图DENSITYPLOT

[seaborn] seaborn学习笔记4 核密度图DENSITYPLOT

时间:2022-12-18 23:22:12浏览次数:63  
标签:plot DENSITYPLOT df seaborn sepal width 笔记 密度 sns

date: 2019-05-31 10:27:35 +0800
tags:
  - seaborn
  - Python
  - 数据分析与可视化

4 核密度图Densityplot(代码下载)

核密度图显示数值变量的分布。它只需要一组数值作为输入。它非常类似于直方图。在seaborn中使用kdeplot函数绘制核密度图,该章节主要内容有:

  1. 基础核密度图绘制 Basic density plot
  2. 核密度图的区间控制 Control bandwidth of density plot
  3. 多个变量的核密度图绘制 Density plot of several variables
  4. 边际核密度图 Marginal Density plot
#调用seaborn
import seaborn as sns
#调用seaborn自带数据集
df = sns.load_dataset('iris')
#显示数据集
df.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

1. 基础核密度图绘制 Basic density plot

  • 基础核密度图函数 default density function
  • 带阴影的核密度图 Density plot with shade
  • 水平核密度图 Horizontal density plot
# 基础核密度图函数 default density function
# 纵坐标为核密度估计值,类似概率密度函数。
# 如x=3.0,纵坐标表示的不是x=3.0处的概率,而是在x=3.0附近取值的可能性估计
sns.kdeplot(df['sepal_width']);
C:\ProgramData\Anaconda3\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval

png

# 带阴影的核密度图 Density plot with shade
# density plot with shade 添加阴影线
sns.kdeplot(df['sepal_width'], shade=True);

png

# 水平核密度图 Horizontal density plot
# 基本所有seaborn绘图函数只要设置vercical就能获得水平方向的图像
sns.kdeplot(df['sepal_width'], shade=True, vertical=True, color="skyblue");

png

2. 核密度图的区间控制 Control bandwidth of density plot

# bw参数控制核密度图的区间
# 其中bw表示根据多少区间范围来计算核密度
# Large bandwidth 
sns.kdeplot(df['sepal_width'], shade=True, bw=.5, color="olive");

png

 # Narrower bandwidth
sns.kdeplot(df['sepal_width'], shade=True, bw=.05, color="olive");

png

3. 多个变量的核密度图绘制 Density plot of several variables

# 有时需要比较多个变量的核密度,可以通过matplotlib创建两个子图,也可以直接画在一张图上
p1=sns.kdeplot(df['sepal_width'], shade=True, color="r")
p1=sns.kdeplot(df['sepal_length'], shade=True, color="b")

png

4. 边际核密度图 Marginal Density plot

# 边际图能够更好变现2个数值变量之间的关系
# No space 无间隔,space表示边缘图和中央图像的间隔,kind表示图像类型
sns.jointplot(x=df["sepal_length"], y=df["sepal_width"], kind='kde', color="grey", space=0);

png

# Huge space 大间隔
sns.jointplot(x=df["sepal_length"], y=df["sepal_width"], kind='kde', space=3);

png

# Make marginal bigger, ratio表示中央图像和边缘图的比例,ratio越大,比例越大
sns.jointplot(x=df["sepal_length"], y=df["sepal_width"], kind='kde',ratio=1);

png

sns.jointplot(x=df["sepal_length"], y=df["sepal_width"], kind='kde',ratio=10);

png

标签:plot,DENSITYPLOT,df,seaborn,sepal,width,笔记,密度,sns
From: https://www.cnblogs.com/luohenyueji/p/16991249.html

相关文章

  • Eigen 学习笔记
    Eigen是一个C++开源库,支持线性代数,矩阵运算,数值分析,矢量计算等一系列算法,方便使用者实现一些复杂的运算Eigen 头文件说明如下: 部分函数用法:MatrixXd:定义一个二维......
  • [seaborn] seaborn学习笔记7 常用参数调整Adjustment of Common Parameters
    date:2019-06-0115:26:17+0800tags:-seaborn-Python-数据分析与可视化7常用参数调整AdjustmentofCommonParameters(代码下载)主要讲述关于seaborn......
  • [seaborn] seaborn学习笔记2 散点图Scatterplot
    2散点图Scatterplot(代码下载)散点图能够显示2个维度上2组数据的值。每个点代表一个观察点。X(水平)和Y(垂直)轴上的位置表示变量的值。研究这两个变量之间的关系是非常有用......
  • [seaborn] seaborn学习笔记1 箱形图Boxplot
    1箱形图Boxplot(代码下载)Boxplot可能是最常见的图形类型之一。它能够很好表示数据中的分布规律。箱型图方框的末尾显示了上下四分位数。极线显示最高和最低值,不包括异常......
  • [seaborn] seaborn学习笔记0 seaborn学习笔记章节
    date:2019-05-2815:54:37+0800tags:-seaborn-Python-数据分析与可视化seaborn学习笔记章节seaborn是一个基于matplotlib的Python数据......
  • (转)expect学习笔记及实例详解
    expect学习笔记及实例详解1.expect是基于tcl演变而来的,所以很多语法和tcl类似,基本的语法如下所示:1.1首行加上/usr/bin/expect1.2spawn:后......
  • 深度学习入门笔记
    深度学习入门笔记编程语言和库Python3.xNumPyMatplotlib常用运算Numpyimportnumpyasnpx=np.array([1.0,2.0])y=np.arange(0,6,0.1)#以0.1为单......
  • ERP 学习笔记 - 生产模块
    生产模块蓝图简介      R/3PP生产计划系统是一个综合性的企业资源计划系统,包括制造执行系统的全部功能。它完整的集成各种应用领域所有业务功能,支持客户订单快速处......
  • python2项目打包rpm笔记
    python2项目打包成rpm包项目目录结构和说明#其中demo的是项目的根目录#pkg是代码逻辑目录#config是配置文件目录#main.py是项目的开始目录#Makefile是打包文件......
  • Python-核心编程-学习笔记
    >下划线标示符_xxx不用'frommoduleimport*'导入__xxx___系统定义名字__xxx类中的私有变量名>模块结构和布局(1)起始行(Unix)(2)模块......