19.md 9.4 KB
Newer Older
W
init  
wizardforcel 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# seaborn.pointplot

```py
seaborn.pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=<function mean>, ci=95, n_boot=1000, units=None, markers='o', linestyles='-', dodge=False, join=True, scale=1, orient=None, color=None, palette=None, errwidth=None, capsize=None, ax=None, **kwargs)
```

Show point estimates and confidence intervals using scatter plot glyphs.

A point plot represents an estimate of central tendency for a numeric variable by the position of scatter plot points and provides some indication of the uncertainty around that estimate using error bars.

Point plots can be more useful than bar plots for focusing comparisons between different levels of one or more categorical variables. They are particularly adept at showing interactions: how the relationship between levels of one categorical variable changes across levels of a second categorical variable. The lines that join each point from the same `hue` level allow interactions to be judged by differences in slope, which is easier for the eyes than comparing the heights of several groups of points or bars.

It is important to keep in mind that a point plot shows only the mean (or other estimator) value, but in many cases it may be more informative to show the distribution of values at each level of the categorical variables. In that case, other approaches such as a box or violin plot may be more appropriate.

Input data can be passed in a variety of formats, including:

*   Vectors of data represented as lists, numpy arrays, or pandas Series objects passed directly to the `x`, `y`, and/or `hue` parameters.
*   A “long-form” DataFrame, in which case the `x`, `y`, and `hue` variables will determine how the data are plotted.
*   A “wide-form” DataFrame, such that each numeric column will be plotted.
*   An array or list of vectors.

In most cases, it is possible to use numpy or Python objects, but pandas objects are preferable because the associated names will be used to annotate the axes. Additionally, you can use Categorical types for the grouping variables to control the order of plot elements.

This function always treats one of the variables as categorical and draws data at ordinal positions (0, 1, … n) on the relevant axis, even when the data has a numeric or date type.

See the [tutorial](../tutorial/categorical.html#categorical-tutorial) for more information.

W
wizardforcel 已提交
28
参数:`x, y, hue`:names of variables in `data` or vector data, optional
W
init  
wizardforcel 已提交
29 30 31

> Inputs for plotting long-form data. See examples for interpretation.

W
wizardforcel 已提交
32
`data`:DataFrame, array, or list of arrays, optional
W
init  
wizardforcel 已提交
33 34 35

> Dataset for plotting. If `x` and `y` are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.

W
wizardforcel 已提交
36
`order, hue_order`:lists of strings, optional
W
init  
wizardforcel 已提交
37 38 39

> Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.

W
wizardforcel 已提交
40
`estimator`:callable that maps vector -&gt; scalar, optional
W
init  
wizardforcel 已提交
41 42 43

> Statistical function to estimate within each categorical bin.

W
wizardforcel 已提交
44
`ci`:float or “sd” or None, optional
W
init  
wizardforcel 已提交
45 46 47

> Size of confidence intervals to draw around estimated values. If “sd”, skip bootstrapping and draw the standard deviation of the observations. If `None`, no bootstrapping will be performed, and error bars will not be drawn.

W
wizardforcel 已提交
48
`n_boot`:int, optional
W
init  
wizardforcel 已提交
49 50 51

> Number of bootstrap iterations to use when computing confidence intervals.

W
wizardforcel 已提交
52
`units`:name of variable in `data` or vector data, optional
W
init  
wizardforcel 已提交
53 54 55

> Identifier of sampling units, which will be used to perform a multilevel bootstrap and account for repeated measures design.

W
wizardforcel 已提交
56
`markers`:string or list of strings, optional
W
init  
wizardforcel 已提交
57 58 59

> Markers to use for each of the `hue` levels.

W
wizardforcel 已提交
60
`linestyles`:string or list of strings, optional
W
init  
wizardforcel 已提交
61 62 63

> Line styles to use for each of the `hue` levels.

W
wizardforcel 已提交
64
`dodge`:bool or float, optional
W
init  
wizardforcel 已提交
65 66 67

> Amount to separate the points for each level of the `hue` variable along the categorical axis.

W
wizardforcel 已提交
68
`join`:bool, optional
W
init  
wizardforcel 已提交
69 70 71

> If `True`, lines will be drawn between point estimates at the same `hue` level.

W
wizardforcel 已提交
72
`scale`:float, optional
W
init  
wizardforcel 已提交
73 74 75

> Scale factor for the plot elements.

W
wizardforcel 已提交
76
`orient`:“v” &#124; “h”, optional
W
init  
wizardforcel 已提交
77 78 79

> 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.

W
wizardforcel 已提交
80
`color`:matplotlib color, optional
W
init  
wizardforcel 已提交
81 82 83

> Color for all of the elements, or seed for a gradient palette.

W
wizardforcel 已提交
84
`palette`:palette name, list, or dict, optional
W
init  
wizardforcel 已提交
85 86 87

> Colors to use for the different levels of the `hue` variable. Should be something that can be interpreted by [`color_palette()`](seaborn.color_palette.html#seaborn.color_palette "seaborn.color_palette"), or a dictionary mapping hue levels to matplotlib colors.

W
wizardforcel 已提交
88
`errwidth`:float, optional
W
init  
wizardforcel 已提交
89 90 91

> Thickness of error bar lines (and caps).

W
wizardforcel 已提交
92
`capsize`:float, optional
W
init  
wizardforcel 已提交
93 94 95

> Width of the “caps” on error bars.

W
wizardforcel 已提交
96
`ax`:matplotlib Axes, optional
W
init  
wizardforcel 已提交
97 98 99

> Axes object to draw the plot onto, otherwise uses the current Axes.

W
wizardforcel 已提交
100 101

返回值:`ax`:matplotlib Axes
W
init  
wizardforcel 已提交
102 103 104

> Returns the Axes object with the plot drawn onto it.

W
wizardforcel 已提交
105

W
init  
wizardforcel 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

See also

Show point estimates and confidence intervals using bars.Combine a categorical plot with a class:<cite>FacetGrid</cite>.

Examples

Draw a set of vertical point plots grouped by a categorical variable:

```py
>>> import seaborn as sns
>>> sns.set(style="darkgrid")
>>> tips = sns.load_dataset("tips")
>>> ax = sns.pointplot(x="time", y="total_bill", data=tips)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-1.png](img/f5eb9519edb052868537ca9735f0f8df.jpg)

Draw a set of vertical points with nested grouping by a two variables:

```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
...                    data=tips)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-2.png](img/864eda3b3c2fcc6b0bdb53c84c3dafcf.jpg)

Separate the points for different hue levels along the categorical axis:

```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
...                    data=tips, dodge=True)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-3.png](img/b7f6772294dcf0d9b7035314c114c54b.jpg)

Use a different marker and line style for the hue levels:

```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
...                    data=tips,
...                    markers=["o", "x"],
...                    linestyles=["-", "--"])

```

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

Draw a set of horizontal points:

```py
>>> ax = sns.pointplot(x="tip", y="day", data=tips)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-5.png](img/4217fbfe6aaba42c4d18a69c5b8c9fc4.jpg)

Don’t draw a line connecting each point:

```py
>>> ax = sns.pointplot(x="tip", y="day", data=tips, join=False)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-6.png](img/96a33f32e85dcced62c9fc4ff063fe3d.jpg)

Use a different color for a single-layer plot:

```py
>>> ax = sns.pointplot("time", y="total_bill", data=tips,
...                    color="#bb3f3f")

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-7.png](img/1e3348f06e5cd7876d5bc530b04d3d93.jpg)

Use a different color palette for the points:

```py
>>> ax = sns.pointplot(x="time", y="total_bill", hue="smoker",
...                    data=tips, palette="Set2")

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-8.png](img/d4a4eeea79c55b0ae9d3088746b6503a.jpg)

Control point order by passing an explicit order:

```py
>>> ax = sns.pointplot(x="time", y="tip", data=tips,
...                    order=["Dinner", "Lunch"])

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-9.png](img/4c08e24283b6829b3d91e3c23de56923.jpg)

Use median as the estimate of central tendency:

```py
>>> from numpy import median
>>> ax = sns.pointplot(x="day", y="tip", data=tips, estimator=median)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-10.png](img/0ec9398faa407996527db66db46c71f2.jpg)

Show the standard error of the mean with the error bars:

```py
>>> ax = sns.pointplot(x="day", y="tip", data=tips, ci=68)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-11.png](img/f9f6dd93a512624527b38dcc26d97e37.jpg)

Show standard deviation of observations instead of a confidence interval:

```py
>>> ax = sns.pointplot(x="day", y="tip", data=tips, ci="sd")

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-12.png](img/f41526e37f8f11614ea339da0e242c51.jpg)

Add “caps” to the error bars:

```py
>>> ax = sns.pointplot(x="day", y="tip", data=tips, capsize=.2)

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-13.png](img/b7df4cf62c681ea39bd145bdb740bc81.jpg)

Use [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") to combine a [`barplot()`](seaborn.barplot.html#seaborn.barplot "seaborn.barplot") and a [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid"). This allows grouping within additional categorical variables. Using [`catplot()`](seaborn.catplot.html#seaborn.catplot "seaborn.catplot") is safer than using [`FacetGrid`](seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") directly, as it ensures synchronization of variable order across facets:

```py
>>> g = sns.catplot(x="sex", y="total_bill",
...                 hue="smoker", col="time",
...                 data=tips, kind="point",
...                 dodge=True,
...                 height=4, aspect=.7);

```

![http://seaborn.pydata.org/_images/seaborn-pointplot-14.png](img/2d47b5f96f08a539147e7f0a71d0aa33.jpg)