[seaborn] seaborn学习笔记4-核密度图DENSITYPLOT
文章目录
4 核密度图Densityplot
(代码下载)
核密度图显示数值变量的分布。它只需要一组数值作为输入。它非常类似于直方图。在seaborn中使用kdeplot函数绘制核密度图,该章节主要内容有:
- 基础核密度图绘制 Basic density plot
- 核密度图的区间控制 Control bandwidth of density plot
- 多个变量的核密度图绘制 Density plot of several variables
- 边际核密度图 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
# 带阴影的核密度图 Density plot with shade
# density plot with shade 添加阴影线
sns.kdeplot(df['sepal_width'], shade=True);
# 水平核密度图 Horizontal density plot
# 基本所有seaborn绘图函数只要设置vercical就能获得水平方向的图像
sns.kdeplot(df['sepal_width'], shade=True, vertical=True, color="skyblue");
2. 核密度图的区间控制 Control bandwidth of density plot
# bw参数控制核密度图的区间
# 其中bw表示根据多少区间范围来计算核密度
# Large bandwidth
sns.kdeplot(df['sepal_width'], shade=True, bw=.5, color="olive");
# Narrower bandwidth
sns.kdeplot(df['sepal_width'], shade=True, bw=.05, color="olive");
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")
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);
# Huge space 大间隔
sns.jointplot(x=df["sepal_length"], y=df["sepal_width"], kind='kde', space=3);
# Make marginal bigger, ratio表示中央图像和边缘图的比例,ratio越大,比例越大
sns.jointplot(x=df["sepal_length"], y=df["sepal_width"], kind='kde',ratio=1);
sns.jointplot(x=df["sepal_length"], y=df["sepal_width"], kind='kde',ratio=10);
[seaborn] seaborn学习笔记4-核密度图DENSITYPLOT的更多相关文章
- Matplotlib学习---用seaborn画直方图,核密度图(histogram, kdeplot)
由于直方图受组距(bin size)影响很大,设置不同的组距可能会产生完全不同的可视化结果.因此我们可以用密度平滑估计来更好地反映数据的真实特征.具体可参见这篇文章:https://blog.csdn ...
- 学习笔记:APP切图那点事儿–详细介绍android和ios平台
学习笔记:APP切图那点事儿–详细介绍android和ios平台 转载自:http://www.woofeng.cn/articles/168.html 版权归原作者所有 作者:亚茹有李 原文地址 ...
- seaborn分布数据可视化:直方图|密度图|散点图
系统自带的数据表格(存放在github上https://github.com/mwaskom/seaborn-data),使用时通过sns.load_dataset('表名称')即可,结果为一个Dat ...
- AC自动机学习笔记-2(Trie图&&last优化)
我是连月更都做不到的蒟蒻博主QwQ 考虑到我太菜了,考完noip就要退役了,所以我决定还是把博客的倒数第二篇博客给写了,也算是填了一个坑吧.(最后一篇?当然是悲怆のnoip退役记啦QAQ) 所以我们今 ...
- 雨痕 的《Python学习笔记》--附脑图(转)
原文:http://www.pythoner.com/148.html 近日,在某微博上看到有人推荐了 雨痕 的<Python学习笔记>,从github上下载下来看了下,确实很不错. 注意 ...
- ArcGIS API for JavaScript 4.2学习笔记[29] 热点(密度)分析——以报警频率为例【使用Geoprocessor类】
这个就颇有插值分析的样子了.也可以说是密度分析.做出来就是一个热力地图的样子. 比如,人口密度,降雨分布等.这都可以由这个例子做出来类似的. 由于上一篇已经介绍过Geoprocessor类和Param ...
- JS表单学习笔记(思维导图)
导图
- JS事件学习笔记(思维导图)
导图
- DOM学习笔记(思维导图)
导图
随机推荐
- 题解 SP24 FCTRL2 - Small factorials
双倍经验. 题意 给\(t\) 组数据,求每组数据中\(n\) 的阶乘. 思路 \(n≤100\) . \(100!\) 肯定爆int128,所以高精呗. 那么就是一个阶乘的板子了,应该不难的吧. 具 ...
- Win环境安装Protobuf 2.0 版本
转载请注明出处: 安装步骤 下载 protobuf-2.5.0.zip 与 protoc-2.5.0-win32.zip 下载链接 : https://github.com/protocolbuffe ...
- Nginx 使用自签名证书实现 https 反代 Spring Boot 中碰到的页面跳转问题
问题一:页面自动跳转到 80 端口 问题描述 最近在使用Nginx反代一个Spring Boot项目中碰到了一个问题,使用 Spring Boot 中的 redirect: 进行页面跳转的时候,通过 ...
- Docker容器化技术
1. 初始Docker 1.1 Docker概念 Docker概念:Docker是一个开源的应用容器引擎 诞生于2013年初,基于Go实现,dotCloud公司出品(后改名为Docker Inc) D ...
- 新建Maui工程运行到IiOS物理设备提示 Could not find any available provisioning profiles for iOS 处理办法
在构建 MAUI App 或 MAUI Blazor 时,您可能会收到以下 Could not find any available provisioning profiles for iOS. Pl ...
- JVM调优工具使用手册
作为Java开发人员,我们肯定知道JDK的bin目录下有"java.exe"."javac.exe"这两个命令工具,这也是我们平时用得最多的工具.但其实bi ...
- Git+Github协作开发流程
采用合作开发者的方式进行协作开发,下面以zlcook和zlserver合作开发iqas-ios-record项目为例进行讲解,zlcook为项目创建者,zlserver为项目参与者.协作开发步骤如下: ...
- kubeEdge的MetaManager模块简介
MetaManager 是edged和edgehub之间的消息处理器,它还负责将元数据存储到轻量级数据库SQLite或从中检索元数据(metadata). 根据以下不同的operation接收不同类型 ...
- 【Java并发011】原理层面:CAS操作全解析
一.前言 volatile关键字是Java51个关键字中用的比较少的一个,它是一个与多线程并发的关键字,但是实际开发中,一般不会用到,使用synchronize+wait()+notify()/not ...
- i春秋Hello World
打开只有一句hello world,直接查看源码,发现一个flag.xmas.js文件 试试直接访问http://106.75.72.168:9999/flag.xmas.js http://106 ...