Seaborn-04-Jointplot两变量图

2016-11-19  本文已影响0人  longgb246
#-*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

绿色:#6AB27B
土色:#a27712
浅紫色:#8172B2
蓝色:#4C72B0
红色:#C44E52

用于2个变量的画图

1、基本参数

seaborn.jointplot(x, y, data=None, kind='scatter', stat_func=<function pearsonr>, 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)
特殊参数:

kind : { “scatter” | “reg” | “resid” | “kde” | “hex” }

基本:
  • <strong>color</strong> : 颜色。参数类型: matplotlib color
  • <strong>size</strong> : 默认 6,图的尺度大小(正方形)。参数类型:numeric
  • <strong>ratio</strong> : 中心图与侧边图的比例,越大、中心图占比越大。参数类型:numeric
  • <strong>space</strong> : 中心图与侧边图的间隔大小。参数类型:numeric
  • <strong>s</strong> : 点的大小。参数类型:numeric
  • <strong>linewidth</strong> : 线的宽度。参数类型:numeric
  • <strong>edgecolor</strong> : 点的边界颜色,默认无色,可以重叠。"w"为白色。参数类型:matplotlib color
  • <strong>{x, y}lim</strong> : x、y轴的范围。参数类型:two-tuples
  • <strong>{joint, marginal, annot}_kws</strong> : dicts Additional keyword arguments for the plot components.
    marginal_kws : 侧边图的信息。例如:dict(bins=15, rug=True)
    annot_kws : 注释的信息。例如:dict(stat="r")
返回:

JointGrid 对象

2、散点图

tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips)
g2 = sns.jointplot(x="total_bill", y="tip", data=tips, kind="scatter")
04_01.png

3、回归图

g3 = sns.jointplot("total_bill", "tip", data=tips, kind="reg")
04_02.png

4、六角图

g4 = sns.jointplot("total_bill", "tip", data=tips, kind="hex")
04_03.png

5、KDE 图

g5 = sns.jointplot("total_bill", "tip", data=tips, kind="kde", space=0, color="#6AB27B")
04_04.png

6、分类变量与连续变量的图

g6 = sns.jointplot("size", "total_bill", data=tips, color="#8172B2")
04_05.png

7、图相交:散点图+KDE 图

iris = sns.load_dataset("iris")
g7 = (sns.jointplot("sepal_length", "sepal_width", data=iris, color="k")
      .plot_joint(sns.kdeplot, zorder=0, n_levels=6))
04_06.png

8、使用参数的画图

g8 = sns.jointplot("petal_length", "sepal_length", data=iris, marginal_kws=dict(bins=15, rug=True), 
                    annot_kws=dict(stat="r"), s=40, edgecolor="w", linewidth=1)
04_07.png
上一篇下一篇

猜你喜欢

热点阅读