seaborn ——Jointplot

深入理解Seaborn库的高级功能(二) Seaborn库通过简单直观的API,极大地简化了数据可视化的过程,同时提供了丰富的绘图选项和自定义功能。无论是用于探索性数据分析,还是最终的报告展示,Seaborn都能够胜任。在实际应用中,结合Seaborn的这些高级功能,能够帮助我们更好地理解数据的内在关系,提升数据分析的深度和质量。通过不断实践和探索,相信你会在Seaborn的使用中获得更多乐趣,并进一步挖掘其强大的潜力。深入了解Python数据可视化库——Seaborn(一) 阅读详情

单个标量或者两个变量的画图

seaborn.jointplot(x, y, data=None, kind=’scatter’, stat_func=, color=None, size=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, joint_kws=None, marginal_kws=None, annot_kws=None, **kwargs)
Parameters:

  • x, y : strings or vectors
    Data or names of variables in data.
  • data : DataFrame, optional
    DataFrame when x and y are variable names.
  • kind : { “scatter” | “reg” | “resid” | “kde” | “hex” }, optional
    Kind of plot to draw.
  • **stat_fun**c : callable or None, optional
    Function used to calculate a statistic about the relationship and annotate the plot. Should map x and y either to a single value or to a (value, p) tuple. Set to None if you don’t want to annotate the plot.
  • color : matplotlib color, optional
    Color used for the plot elements.
  • size : numeric, optional
    Size of the figure (it will be square).
  • ratio : numeric, optional
    Ratio of joint axes size to marginal axes height.
  • space : numeric, optional
    Space between the joint and marginal axes
  • dropna : bool, optional
    If True, remove observations that are missing from x and y.
  • {x, y}lim : two-tuples, optional
    Axis limits to set before plotting.
  • {joint, marginal, annot}_kws : dicts, optional
    Additional keyword arguments for the plot components.
  • kwargs : key, value pairings
    Additional keyword arguments are passed to the function used to draw the plot on the joint Axes, superseding items in the joint_kws dictionary.
    Returns:
    grid : JointGrid
    JointGrid object with the plot on it.

class seaborn.JointGrid(x, y, data=None, size=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None)
Parameters:

  • x, y : strings or vectors
    Data or names of variables in data.
  • data : DataFrame, optional
    DataFrame when x and y are variable names.
  • size : numeric
    Size of each side of the figure in inches (it will be square).
  • ratio : numeric
    Ratio of joint axes size to marginal axes height.
  • space : numeric, optional
    Space between the joint and marginal axes
  • dropna : bool, optional
    If True, remove observations that are missing from x and y.
  • {x, y}lim : two-tuples, optional
    Axis limits to set before plotting.
%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import scipy.stats as sci
sns.set_style('darkgrid')
sns.set_context('talk')
  • jointplot是画两个变量或者单变量的图像,是对JointGrid类的实现
  • x,y为DataFrame中的列名或者是两组数据,data指向dataframe ,kind是你想要画图的类型
  • stat_func 用于计算统计量关系的函数
  • kind 图形的类型scatter,reg,resid,kde,hex
  • 以下均是以股票数据作为演示
stock=pd.read_csv('sample.csv',index_col=0)
sns.jointplot(x='v_ma5',y='price_change',data=stock,kind='kde')

sns.jointplot(x='v_ma5',y='price_change',data=stock,kind='reg')

  • space 定义的是上,右图像距离中间图像的距离
  • color 定义的是图形的整体颜色
  • edgecolor 定义中间图形散点的颜色
  • linewidth 定义图形线条或者散点图的大小
  • marginal_kws 定义边界上hist的参数,以字典的形式传参

sns.jointplot(x='v_ma5',y='price_change',data=stock,kind='reg',stat_func=sci.pearsonr,space=0,color='r')

g=(sns.jointplot(x='v_ma5',y='price_change',data=stock,edgecolor="g").set_axis_labels("X","Y"),)

sns.jointplot(x='v_ma5',y='price_change',data=stock,linewidth=6,marginal_kws=dict(bins=20, rug=True))

sns.jointplot(x='v_ma5',y='price_change',data=stock,annot_kws=dict(stat="r"))
<seaborn.axisgrid.JointGrid at 0x29628eb8>

#初始化类
g=sns.JointGrid(x='v_ma5',y='price_change',data=stock,space=0.5,ratio=5)

#join 和marginals分开画
g=sns.JointGrid(x='v_ma5',y='price_change',data=stock,space=0.5,ratio=5)
g=g.plot(sns.regplot,sns.distplot)

g=sns.JointGrid(x='v_ma5',y='price_change',data=stock,space=0.5,ratio=5)
g=g.plot_joint(plt.scatter,color='.3',edgecolor='r')
g=g.plot_marginals(sns.distplot,kde=False)

#marginal 的图像和join的图像变量不一致
from scipy import stats
g=sns.JointGrid(x='v_ma5',y='price_change',data=stock,space=0.5,ratio=5)
g=g.plot_joint(plt.scatter,color='.3',edgecolor='r')
_=g.ax_marg_x.hist(stock.v_ma10,color='r',alpha=.6,bins=50)
_=g.ax_marg_y.hist(stock.low,color='y',orientation="horizontal",bins=20)
g = g.annotate(stats.pearsonr)
#annotate  注释;注解

  • 使用不同函数给join形成注释
from scipy import stats
g=sns.JointGrid(x='v_ma5',y='price_change',data=stock,space=0.5,ratio=5)
g=g.plot_joint(plt.scatter,color='.3',edgecolor='r')
_=g.ax_marg_x.hist(stock.v_ma10,color='r',alpha=.6,bins=50)
_=g.ax_marg_y.hist(stock.low,color='y',orientation="horizontal",bins=20)
rquare=lambda a,b:stats.pearsonr(a,b)[0]**2
g=g.annotate(rquare,template='{stat}:{val:.2f}',stat='$R^2$',loc='upper left',fontsize=12)

  • shade 表示是吗画阴影部分
g=sns.JointGrid(x='v_ma5',y='price_change',data=stock,space=0.5,ratio=5)
g = g.plot_joint(sns.kdeplot, cmap="Reds_d")
g = g.plot_marginals(sns.kdeplot, color="r", shade=True)

核密度函数

%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import scipy.stats as sci
sns.set_style('darkgrid')
sns.set_context('talk')

核密度函数kde(kernel density estimate)
kdeplot画单变量或者双因子的核密度函数
seaborn.kdeplot(data, data2=None, shade=False, vertical=False, kernel=’gau’, bw=’scott’, gridsize=100, cut=3, clip=None, legend=True, cumulative=False, shade_lowest=True, ax=None, **kwargs)
Parameters:
- data : 1d array-like
Input data.
- data2: 1d array-like, optional
Second input data. If present, a bivariate KDE will be estimated.
- shade : bool, optional
If True, shade in the area under the KDE curve (or draw with filled contours when data is bivariate).
vertical : bool, optional
If True, density is on x-axis.
- kernel : {‘gau’ | ‘cos’ | ‘biw’ | ‘epa’ | ‘tri’ | ‘triw’ }, optional
Code for shape of kernel to fit with. Bivariate KDE can only use gaussian kernel.
- bw : {‘scott’ | ‘silverman’ | scalar | pair of scalars }, optional
Name of reference method to determine kernel size, scalar factor, or scalar for each dimension of the bivariate plot.
- gridsize : int, optional
Number of discrete points in the evaluation grid.
- cut : scalar, optional
Draw the estimate to cut * bw from the extreme data points.
clip : pair of scalars, or pair of pair of scalars, optional
Lower and upper bounds for datapoints used to fit KDE. Can provide a pair of (low, high) bounds for bivariate plots.
- legend : bool, optional
If True, add a legend or label the axes when possible.
- cumulative : bool, optional
If True, draw the cumulative distribution estimated by the kde.
- shade_lowest : bool, optional
If True, shade the lowest contour of a bivariate KDE plot. Not relevant when drawing a univariate plot or when shade=False. Setting this to False can be useful when you want multiple densities on the same Axes.
- ax : matplotlib axis, optional
Axis to plot on, otherwise uses current axis.
kwargs : key, value pairings
Other keyword arguments are passed to plt.plot() or plt.contour{f} depending on whether a univariate or bivariate plot is being drawn.
Returns:
ax : matplotlib Axes
Axes with plot.

stock=pd.read_csv('sample.csv',index_col=0)
ax=sns.kdeplot(stock.open,shade=True,color='r',cumulative=True)

ax=sns.kdeplot(stock.open,shade=True,color='r',vertical=True)

sns.kdeplot(stock.open,stock.v_ma10,shade=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1f87f5c0>

countplot
Parameters:

  • x, y, hue : names of variables in data or vector data, optional
    Inputs for plotting long-form data. See examples for interpretation.
  • data : DataFrame, array, or list of arrays, optional
    Dataset for plotting. If x and y are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.
  • order, hue_order : lists of strings, optional
    Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
  • orient : “v” | “h”, optional
    Orientation of the plot (vertical or horizontal). This is usually inferred from the dtype of the input variables, but can be used to specify when the “categorical” variable is a numeric or when plotting wide-form data.
  • color : matplotlib color, optional
    Color for all of the elements, or seed for light_palette() when using hue nesting.
  • palette : seaborn color palette or dict, optional
    Colors to use for the different levels of the hue variable. Should be something that can be interpreted by color_palette(), or a dictionary mapping hue levels to matplotlib colors.
  • saturation : float, optional
    Proportion of the original saturation to draw colors at. Large patches often look better with slightly desaturated colors, but set this to 1 if you want the plot colors to perfectly match the input color spec.
  • ax : matplotlib Axes, optional
    Axes object to draw the plot onto, otherwise uses the current Axes.
  • kwargs : key, value mappings
    Other keyword arguments are passed to plt.bar.
sns.countplot(x='code',data=stock)

seaborn中jointplot的2D KDE自定义画法:商用数据可视化 在商业可视化领域,对于双特征的KDE等高线图,让等高线变化有了色彩的变化的感觉,两边的小图加阴影,也自定义了调色盘,设置了独特的主题 阅读详情

相关推荐

Seaborn中怎样绘制双变量分布图?

两个变量的二元分布可视化也很有用。在 Seaborn中最简单的方法是使用 jointplot()函数,该函数可以创建一个多面板图形,比如散点图、二维直方图、核密度估计等,以显示两个变量之间的双变量关系及每个变量在单坐标轴上的单变量分布。jointplot()函数的语法格式如下。上述函数中常用参数的含义如下:(1) kind:表示绘制图形的类型。(2) stat_func:用于计算有关关系的统计量并标注图。(3) color:表示绘图元素的颜色。(4) size:用于设置图的大小(正方形)。

CZ-001的博客 990

seaborn系列 (15) | 双变量关系图jointplot()

目录双变量关系图函数原型参数解读案例教程案例地址 双变量关系图 在默认情况下双变量关系图是散点图与直方图组合的联合直方图,可以通过设置kind来改变联合直方图。 函数原型 seaborn.jointplot(x, y, data=None, kind='scatter', stat_func=None, color=None, height=6, ...

脑机接口社区 6790

Seaborn双变量分布jointplot的坐标轴标签设置

详细版本见个人博客:Seaborn双变量分布jointplot的坐标轴标签设置 一、问题描述 我采用jointplot()进行双变量分布绘图: sns.jointplot(x, y) 但是没法通过plt.xlabel来修改它的坐标轴标签。 二、解决办法 这里要用到JointGrid对象。 jointplot()函数基于JointGrid对象来控制图形。我们可以直接使用JointGrid来获得...

dta0502的博客 9563

Py之seaborn:数据可视化seaborn库(三)的矩阵图可视化之jointplot/JointGrid/pairplot/PairGrid/FacetGrid密度图等的函数源代码详解之最强攻略

​ Py之seaborn:数据可视化seaborn库(三)的矩阵图可视化之jointplot/JointGrid/pairplot/PairGrid/FacetGrid折线图/柱状图+散点图/矩形密度图的函数源代码详解之最强攻略 目录 三、矩阵图可视化 相关文章 Py之seaborn:seaborn库的简介、安装、使用方法之详细攻略 Py之seaborn:数据可视化seaborn库(一)的柱状图、箱线图(置信区间图)、散点图/折线图、核密度图/等高线图、盒形图/小提琴图

头部AI社区如有邀博主AI主题演讲请私信—心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,专注,谦虚,自律,反思,成长,还算比较正能量的博主,公益免费传播…内心特别想在AI界做出一些可以推进历史进程影响力的技术(兴趣使然,有点小情怀,也有点使命感呀 5711

【Seaborn】组合图表:PairPlot和JointPlot

会自动根据数据集中的度量字段自动生成图表,而不需要我们依次去绑定数据;默认对角线是使用直方图,两侧散点图; 如一样,一样也会根据数据集的度量字段自动生成图表,而不需要依次去指定;...

AwesomeTang 1529

Seaborn中的绘制双变量分布—jointplot()函数方法

          两个变量的二元分布可视化也很有用。在Seaborn中最简单的方法是使用jointplot()函数,该函数可以创建一个多面板图形,比如散点图、二维直方图、核密度估计等,以显示两个变量之间的双变量关系及每个变量在单独坐标轴上的单变量分布。           jointplot()函数的语法格式

KJ.JK 8277

详解seaborn中的kdeplot、rugplot、distplot与jointplot

简介 seaborn是Python中基于matplotlib的具有更多可视化功能和更优美绘图风格的绘图模块,当我们想要探索单个或一对数据分布上的特征时,可以使用到seaborn中内置的若干函数对数据的分布进行多种多样的可视化,本文以jupyter notebook为编辑工具,针对seaborn中的kdeplot、rugplot、distplot和jointplot,对其参数设置和具体用法进行详细介绍。 kdeplot seaborn中的kdeplot可用于对单变量和双变量进行核密度估计并可视化,其主要参数如

sunghosts的专栏 1万+

seaborn使用jointplot函数为散点图添加边缘图、为散点图添加边缘直方图(Marginal Plot in Python with Seaborn jointplot)

seaborn使用jointplot函数为散点图添加边缘图、为散点图添加边缘直方图(Marginal Plot in Python with Seaborn jointplot)

data+scenario+science+insight 912

seaborn.jointplot()

seaborn.jointplot()

wjj2586590669的博客 595

DOSBOX 0.74模拟器安装Windows 95

DosBox本身带有5.0版的DOS系统,启动后虚拟一个Z盘存放有Dosbox特有的外部指令,如config.com、imgmount.com等,经测试,可以顺利安装各版本的windows 3.1系统,但是不能安装win95,需要用原版的dos镜像启动才能安装。1. 获取启动盘镜像文件 下载Win95启动软盘镜像文件,名为boot.img,放到DosBox 0.74的目录下。2. 制作硬盘镜像文件

xjnzhidao的博客 9310

mtk-drm commit送显流程(二):内核态atomic_commit实现解析

本文深入解析了mtk-drm框架中atomic_commit机制的内核态实现流程,详细介绍了从用户态触发到硬件提交的完整调用链,包括状态检查、硬件提交等关键阶段。特别分析了MTK平台在动态刷新率、内存带宽优化等方面的特有实现策略,为开发者提供了调试技巧和常见问题解决方案。

weixin_30839881的博客 1305

【seaborn】jointplot 改变图片长宽比,非方形

最近开始写论文了,画好看图是非常有必要的。matplolib虽然能满足基础需求,但是总感觉没那么高大上。简单接触seaborn后,发现确实集成度很高,很简单的API就可以画出美观的数据图。但是市面上应该还没有系统的数据,主要参考都是官网的例子。出现一些其他问题就只能自己想办法去网上搜了。 比如今天的使用jointplot时发现,默认格式图像长宽比是1:1,传统matplotlib中的figsize关键字都无法改变图像的尺寸。而 jointplot关键字中只有height,无法改变图像的高度。 height

Forrest97的博客 1627

用STM32的SPI接口读取MT6835磁编码器,手把手教你避开数据读取的坑

本文详细介绍了如何使用STM32的SPI接口读取MT6835磁编码器,并提供了21个实战细节与避坑指南。从硬件连接、SPI配置到数据解析和实时调试,全面解析了读取位置信息过程中的常见问题及解决方案,帮助工程师在工业控制、伺服电机等场景中高效应用AMR技术。

weixin_30729609的博客 1441

seaborn.jointplot

【代码】seaborn.jointplot。

m0_62224692的博客 278

油气井管柱力学发展

油气井管柱力学发展 1 石油管柱力学问题的发复杂性 1)油气管柱动力学的非线性 钻井中钻柱在重力、钻压、扭矩、钻井液浮力和井壁约束等作用下,产生三维变形。一方面随井眼轴线的弯曲而弯曲,这一变形被称为管柱的初位移;另一方面,管柱在运动过程中相对井眼轴线也有变形,这种变形被称为计算位移。管柱大变形主要表现在初位移部分,计算位移相对很小。大曲率井眼中管柱产生大挠度,但管柱很长且柔软性较好,变形一般仍保持...

weixin_43831995的博客 951

SAP-ABAP:SAP Open SQL 分页技术深度解析:语法、性能陷阱与最佳实践

SAP Open SQL 分页技术深度解析:语法、性能陷阱与最佳实践

baidu_35680696的博客 634

【Seaborn-驯化】一文学会seaborn中的双变量关系图使用技巧:jointplot

jointplot 是 Seaborn 库中的一个强大工具,用于可视化两个变量的联合分布。它结合了散点图、直方图、核密度估计(KDE)等多种图表类型,提供了对数据分布和关系的深入理解。联合分布:表示两个随机变量取值的概率分布。边缘分布:在联合分布中,分别固定一个变量,观察另一个变量的分布。散点图:展示两个变量之间的点对点关系。KDE:核密度估计,用于平滑地展示数据的概率密度函数。

志在创建优质博客、通俗易懂、助力大家提高学习效率! 1266

“华为杯”研究生数学建模竞赛2020年-【华为杯】B题:汽油辛烷值优化建模(附优秀论文)

摘 要:本文通过机器学习算法和数据挖掘技术,建立了汽油辛烷值(RON)损失的预测模型,在保证汽油产品脱硫效果的前提下,以降低汽油辛烷值损失在30%以上为目标,给出每个样本的优化操作条件。针对第一问,对285号和313号原始数据用给定的数据处理规范进行预处理,对每一列变量求期望,得到最终的数据补充到相应的样本编号。针对第二问,首先对数据样本按照最大最小限幅以及拉依达法则进行列变量清洗,通过两轮特征筛选确定变量:结合处理后的数据,针对产品中硫含量、RON损失值用。

getusushu的博客 1251

详解seaborn图表中的kdeplot、rugplot、distplot与jointplot

seaborn是Python中基于matplotlib的具有更多可视化功能和更优美绘图风格的绘图模块,当我们想要探索单个或一对数据分布上的特征时,可以使用到seaborn中内置的若干函数对数据的分布进行多种多样的可视化。本文以jupyter notebook为编辑工具,针对seaborn中的kdeplot、rugplot、distplot和jointplot,对其参数设置和具体用法进行详细介绍。

分享Python、数据分析、人工智能前沿知识 3245

数据库小技能:数据导入脚本

背景:版本大升级,从2.0升级到3.0 ,服务端开发语言从c#换到java语言。数据库类型从microsalft sql server 换到mysql。数据来源于微信,用于查询卡bin。

专注于计算机研发知识和资讯分享 774

YOLO11涨点优化:注意力魔改 | 引入Deformable Attention (可变形注意力),灵活感受野自适应复杂形变目标

Deformable Attention为YOLO11带来的不仅是2.6个百分点的mAP提升,更是一种全新的“形变感知”范式。标准卷积的固定感受野在非刚性目标、多尺度变化和遮挡场景下力不从心——Deformable Attention恰好填补了这一空白。从架构设计到代码实现,从竞品对比到部署方案,从生态工具到安全风险,本文覆盖了将Deformable Attention引入YOLO11所需的全部知识链路。

2601_95807009的博客 286

Seaborn-04-Jointplot两变量图

#-*- coding:utf-8 -*- import numpy as np import matplotlib.pyplot as plt import seaborn as sns 绿色:#6AB27B 土色:#a27712 浅紫色:#8172B2 用于2个变量的画图1、基本参数seaborn.jointplot(x, y, data=None, kind=’scatter’

longgb123的博客 8887

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

python对角线图_python – 在Seaborn Jointplot上绘制对角线(相等的线)

错误是一个有用的暗示:JointPlot是子图的集合,你必须找到特定的斧头来绘制.修改Seaborn示例:import numpy as npimport pandas as pdimport seaborn as snsfrom matplotlib.pyplot import showsns.set(style="white")# Generate a random correlated bi...

weixin_39787089的博客 744

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Python3 - seaborn 练习题: FacetGrid, swarmplot, countplot, heatmap, boxplot, distplot, jointplot 有料

是在Jupyter Notebooks上进行练习,要想了解如何创建Jupyter Notebooks, 请点击这里 要想了解练习中的知识,请翻看这里来了解~~ 练习使用的数据: import seaborn as sns import matplotlib.pyplot as plt sns.set_style('whitegrid') titanic = sns.load_dataset('titanic') titanic.head() 结果如下: 使用jointplot(): sns.jointp

CHNMSCS 481

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Python3 - seaborn的使用:distplot(), jointplot(), pairplot(), rugplot(), scatterplot(), kdeplot()

博主都是在Jupyter Notebooks上进行练习的,如有想要使用Jupyter Notebooks, 请点击这里 直接上代码: import seaborn as sns tips = sns.load_dataset('tips') print(tips.head()) 结果如下: 使用distplot(): print(sns.distplot(tips['total_bill'])) 结果如下: # kde: Whether to plot a gaussian kernel dens

CHNMSCS 864

python画密度散点图_Python可视化24 | Seaborn以绘制多元分布图(jointplot | jointgrid),24seaborn,变量,jointplotJointGrid...

本文介绍两个变量之间的分布图(Draw a plot oftwo variableswith bivariate and univariate graphs.)。本文内容速看seaborn.jointplot绘制两个变量分布图seaborn.JointGrid绘制两个变量分布图(更个性化)目录1、绘图数据准备还是鸢尾花iris数据集:鸢尾花iris数据集介绍#导入本帖要用到的库,声明如下:impo...

weixin_39614754的博客 924
上一篇: Seaborn-PairGrid
下一篇: 独立性检验的基本思想和初步应用
宁静致远wyd
博客等级 码龄15年 75粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值