22.md 4.3 KB
Newer Older
W
init  
wizardforcel 已提交
1 2
# seaborn.jointplot

S
Stuming 已提交
3 4
> 译者:[Stuming](https://github.com/Stuming)

W
init  
wizardforcel 已提交
5 6 7 8
```py
seaborn.jointplot(x, y, data=None, kind='scatter', stat_func=None, color=None, height=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, joint_kws=None, marginal_kws=None, annot_kws=None, **kwargs)
```

S
Stuming 已提交
9
绘制两个变量的双变量及单变量图。
W
init  
wizardforcel 已提交
10

S
Stuming 已提交
11
这个函数提供调用[`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid "seaborn.JointGrid")类的便捷接口,以及一些封装好的绘图类型。这是一个轻量级的封装,如果需要更多的灵活性,应当直接使用[`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid "seaborn.JointGrid").
W
init  
wizardforcel 已提交
12

S
Stuming 已提交
13
参数:`x, y`:strings或者vectors
W
init  
wizardforcel 已提交
14

S
Stuming 已提交
15
> `data`中的数据或者变量名。
W
init  
wizardforcel 已提交
16

S
Stuming 已提交
17
`data`:DataFrame, 可选
W
init  
wizardforcel 已提交
18

S
Stuming 已提交
19
> 当`x`和`y`为变量名时的DataFrame.
W
init  
wizardforcel 已提交
20

S
Stuming 已提交
21
`kind`:{ “scatter” | “reg” | “resid” | “kde” | “hex” }, 可选
W
init  
wizardforcel 已提交
22

S
Stuming 已提交
23
> 绘制图像的类型。
W
init  
wizardforcel 已提交
24

S
Stuming 已提交
25
`stat_func`:可调用的,或者None, 可选
W
init  
wizardforcel 已提交
26

S
Stuming 已提交
27
> 已过时
W
init  
wizardforcel 已提交
28

S
Stuming 已提交
29
`color`:matplotlib颜色, 可选
W
init  
wizardforcel 已提交
30

S
Stuming 已提交
31
> 用于绘制元素的颜色。
W
init  
wizardforcel 已提交
32

S
Stuming 已提交
33
`height`:numeric, 可选
W
init  
wizardforcel 已提交
34

S
Stuming 已提交
35
> 图像的尺寸(方形)。
W
init  
wizardforcel 已提交
36

S
Stuming 已提交
37
`ratio`:numeric, 可选
W
init  
wizardforcel 已提交
38

S
Stuming 已提交
39
>  中心轴的高度与侧边轴高度的比例
W
init  
wizardforcel 已提交
40

S
Stuming 已提交
41
`space`:numeric, 可选
W
init  
wizardforcel 已提交
42

S
Stuming 已提交
43
> 中心和侧边轴的间隔大小
W
init  
wizardforcel 已提交
44

S
Stuming 已提交
45
`dropna`:bool, 可选
W
init  
wizardforcel 已提交
46

S
Stuming 已提交
47
> 如果为True, 移除`x`和`y`中的缺失值。
W
init  
wizardforcel 已提交
48

S
Stuming 已提交
49
`{x, y}lim`:two-tuples, 可选
W
init  
wizardforcel 已提交
50

S
Stuming 已提交
51
> 绘制前设置轴的范围。
W
init  
wizardforcel 已提交
52

S
Stuming 已提交
53
`{joint, marginal, annot}_kws`:dicts, 可选
W
init  
wizardforcel 已提交
54

S
Stuming 已提交
55
> 额外的关键字参数。
W
init  
wizardforcel 已提交
56

S
Stuming 已提交
57
`kwargs`:键值对
W
init  
wizardforcel 已提交
58

S
Stuming 已提交
59
> 额外的关键字参数会被传给绘制中心轴图像的函数,取代`joint_kws`字典中的项。
W
init  
wizardforcel 已提交
60

W
wizardforcel 已提交
61 62

返回值:`grid`[`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid "seaborn.JointGrid")
W
init  
wizardforcel 已提交
63

S
Stuming 已提交
64
> [`JointGrid`](seaborn.JointGrid.html#seaborn.JointGrid "seaborn.JointGrid")对象.
W
init  
wizardforcel 已提交
65

W
wizardforcel 已提交
66

W
init  
wizardforcel 已提交
67

S
Stuming 已提交
68
参考
W
init  
wizardforcel 已提交
69

S
Stuming 已提交
70
绘制图像的Grid类。如果需要更多的灵活性,可以直接使用Grid类。
W
init  
wizardforcel 已提交
71

S
Stuming 已提交
72
示例
W
init  
wizardforcel 已提交
73

S
Stuming 已提交
74
绘制带有侧边直方图的散点图:
W
init  
wizardforcel 已提交
75 76 77 78 79 80 81 82 83 84 85

```py
>>> import numpy as np, pandas as pd; np.random.seed(0)
>>> import seaborn as sns; sns.set(style="white", color_codes=True)
>>> tips = sns.load_dataset("tips")
>>> g = sns.jointplot(x="total_bill", y="tip", data=tips)

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-1.png](img/48d5020fcbaa6d2f36aae520f84a6234.jpg)

S
Stuming 已提交
86
添加回归线及核密度拟合:
W
init  
wizardforcel 已提交
87 88 89 90 91 92 93 94

```py
>>> g = sns.jointplot("total_bill", "tip", data=tips, kind="reg")

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-2.png](img/8434c101b75c73a9e1b8dfb89975a2b5.jpg)

S
Stuming 已提交
95
将散点图替换为六角形箱体图:
W
init  
wizardforcel 已提交
96 97 98 99 100 101 102 103

```py
>>> g = sns.jointplot("total_bill", "tip", data=tips, kind="hex")

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-3.png](img/6d5c569bf97b1f683a2ec921e1031112.jpg)

S
Stuming 已提交
104
将散点图和直方图替换为密度估计,并且将侧边轴与中心轴对齐:
W
init  
wizardforcel 已提交
105 106 107 108 109 110 111 112 113 114

```py
>>> iris = sns.load_dataset("iris")
>>> g = sns.jointplot("sepal_width", "petal_length", data=iris,
...                   kind="kde", space=0, color="g")

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-4.png](img/c2c70e8889861b837b4fd45d707a6616.jpg)

S
Stuming 已提交
115
绘制散点图,添加中心密度估计:
W
init  
wizardforcel 已提交
116 117 118 119 120 121 122 123 124 125

```py
>>> g = (sns.jointplot("sepal_length", "sepal_width",
...                    data=iris, color="k")
...         .plot_joint(sns.kdeplot, zorder=0, n_levels=6))

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-5.png](img/b6895c87c4fa5a7fa1dc151dc3e5b385.jpg)

S
Stuming 已提交
126
不适用Pandas, 直接传输向量,随后给轴命名:
W
init  
wizardforcel 已提交
127 128 129 130 131 132 133 134 135 136

```py
>>> x, y = np.random.randn(2, 300)
>>> g = (sns.jointplot(x, y, kind="hex")
...         .set_axis_labels("x", "y"))

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-6.png](img/72b1f526c884ba4a6a285f1e8723013e.jpg)

S
Stuming 已提交
137
绘制侧边图空间更大的图像:
W
init  
wizardforcel 已提交
138 139 140 141 142 143 144 145 146

```py
>>> g = sns.jointplot("total_bill", "tip", data=tips,
...                   height=5, ratio=3, color="g")

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-7.png](img/ddcf0a83320e56c75f2d5d15ff29c874.jpg)

S
Stuming 已提交
147
传递关键字参数给后续绘制函数:
W
init  
wizardforcel 已提交
148 149 150 151 152 153 154 155 156 157

```py
>>> g = 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)

```

![http://seaborn.pydata.org/_images/seaborn-jointplot-8.png](img/0fa41716b87d635876d921fc9ab967ea.jpg)