提交 94d15f17 编写于 作者: L leijuzi

add 11,md

上级 19519035
# seaborn.scatterplot
### seaborn.scatterplot
```py
```python
seaborn.scatterplot(x=None, y=None, hue=None, style=None, size=None, data=None, palette=None, hue_order=None, hue_norm=None, sizes=None, size_order=None, size_norm=None, markers=True, style_order=None, x_bins=None, y_bins=None, units=None, estimator=None, ci=95, n_boot=1000, alpha='auto', x_jitter=None, y_jitter=None, legend='brief', ax=None, **kwargs)
```
绘制几个语义分组的散点图。
Draw a scatter plot with possibility of several semantic groupings.
数据的不同子集的x和y之间的关系可以用hue, size, style这三个参数来控制绘图属性。
这些参数控制用于识别不同子集的视觉语义信息,三种语义类型全部使用的话可以独立显示三个维度,
但是这种风格的绘图很难解释或者说没大部分时候什么效果。使用过多的语义信息
(例如:对同一个变量同时使用hue和style)对作图来说是很有帮助同时也更容易理解。
The relationship between `x` and `y` can be shown for different subsets of the data using the `hue`, `size`, and `style` parameters. These parameters control what visual semantics are used to identify the different subsets. It is possible to show up to three dimensions independently by using all three semantic types, but this style of plot can be hard to interpret and is often ineffective. Using redundant semantics (i.e. both `hue` and `style` for the same variable) can be helpful for making graphics more accessible.
阅读下面的教程可以get更多信息哦。
See the [tutorial](../tutorial/relational.html#relational-tutorial) for more information.
**参数**:
x ,y: data或是向量data里面的变量名字,可选择
>* 输入数据的变量,必须是数字,可以直接传递数据或引用数据中的列
参数:`x, y`:names of variables in `data` or vector data, optional
hue: data或是向量data里面的变量名字,可选择
>* 将产生不同大小的点的变量进行分组,可以是类别也可以是数字,
但是大小映射在后一种情况会有不同的表现
> Input data variables; must be numeric. Can pass data directly or reference columns in `data`.
style: data或是向量data里面的变量名字,可选择
>* 将产生不同标记的点的变量进行分类,可以有一个数字类型,但是这个数字会被当作类别
`hue`:name of variables in `data` or vector data, optional
data: DataFrame
>* Tidy (“long-form”) dataframe 它的每一列是一个变量,每一行是一个观测值
> Grouping variable that will produce points with different colors. Can be either categorical or numeric, although color mapping will behave differently in latter case.
plaette : 调色板的名字、列表或字典,可选
>* 用于不同level的hue变量的颜色,应该是可以被 color_palette() 执行的something,
或者是一个可以对matplotlib colors映射hue级别的字典。
`size`:name of variables in `data` or vector data, optional
hue_order: 列表,可选
>* 对hue变量的级别的表象有特定的顺序,否则的话,顺序由data决定。当hue是数字的时候与它不相关
> Grouping variable that will produce points with different sizes. Can be either categorical or numeric, although size mapping will behave differently in latter case.
hue_norm: 元组或标准化的对象,可选
>* 当hue变量是数字的时候,应用于hue变量的色彩映射的数据单元中的标准化。如果是类别则不相关
`style`:name of variables in `data` or vector data, optional
sizes: 列表,字典或元组,可选
>* 当使用size的时候,用来决定如何选择sizes的一个对象。可以一直是一个包含size数值的列表,
或者是一个映射变量size级别到sizes的字典。当size是数字时,sizes可以是包含size最大值
和最小值的元组,其他的值都会标准化到这个元组指定的范围
> Grouping variable that will produce points with different markers. Can have a numeric dtype but will always be treated as categorical.
size_order: 元组,可选
>* size变量级别表现的特定顺序,否则顺序由data决定,当size变量是数字时不相关
`data`:DataFrame
size_norm:元组或标准化的对象,可选
>* 当变量size是数字时,用于缩放绘图对象的数据单元中的标准化
> Tidy (“long-form”) dataframe where each column is a variable and each row is an observation.
makers: 布尔型,列表或字典,可选
>* 决定如何绘制不同级别style的标志符号。设置为True会使用默认的标志符号,或者通过一系列标志
或者一个字典映射style变量的级别到markers。设置为False会绘制无标志的线。
Markers在matplotlib中指定
`palette`:palette name, list, or dict, optional
style_order: 列表,可选
>* 对于style变量级别表象的特定顺序,否则由data决定,当style是数字时不相关
> 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.
{x,y}_bins: 元组,矩阵或函数
>* 暂时没有什么功能
`hue_order`:list, optional
units: {long_form_var}
>* 分组特定的样本单元。使用时,将为每个具有适当的语义的单元绘制一根单独的线,
但不会添加任何图例条目。 当不需要确切的身份时,可用于显示实验重复的分布。
目前没啥作用
> Specified order for the appearance of the `hue` variable levels, otherwise they are determined from the data. Not relevant when the `hue` variable is numeric.
estimator: pandas方法的名称,或者可调用的方法或者是None,可选
>* 聚类同一个x上多个观察值y,如果是None,所有的观察值都会绘制,目前暂无功能
`hue_norm`:tuple or Normalize object, optional
ci: 整型或 'sd' or None,可选
>* 与估算器聚合时绘制的置信区间的大小。 “sd”表示绘制数据的标准偏差。 设置为None将跳过自举。 目前无功能。
> Normalization in data units for colormap applied to the `hue` variable when it is numeric. Not relevant if it is categorical.
n_boot: 整型,可选
>* 自举法的数量,用于计算区间的置信度,暂无功能
`sizes`:list, dict, or tuple, optional
alpha: 浮点型
>* 设置点的不透明度
> An object that determines how sizes are chosen when `size` is used. It can always be a list of size values or a dict mapping levels of the `size` variable to sizes. When `size` is numeric, it can also be a tuple specifying the minimum and maximum size to use such that other values are normalized within this range.
{x,y}_jitter:布尔或者浮点型
>* 暂无功能
`size_order`:list, optional
legend:“brief”, “full”, or False, 可选
>* 绘制图例的方式。如果为“brief" 数字hue和size变量会代表一个样本,即便有不同的值
if "full", 每一个分组都有图例。if False 不绘制也不添加图例
> Specified order for appearance of the `size` variable levels, otherwise they are determined from the data. Not relevant when the `size` variable is numeric.
ax: matplotlib坐标轴,可选
>* 绘制图像的坐标对象,否则使用当前坐标轴
`size_norm`:tuple or Normalize object, optional
kwargs:键值映射对
>* 在绘制的时候其他的键会传递给plt.scatter
> Normalization in data units for scaling plot objects when the `size` variable is numeric.
返回值:ax:matplotlib 坐标轴
>* 返回绘制所需的坐标
`markers`:boolean, list, or dictionary, optional
请参阅官方文档
> Object determining how to draw the markers for different levels of the `style` variable. Setting to `True` will use default markers, or you can pass a list of markers or a dictionary mapping levels of the `style` variable to markers. Setting to `False` will draw marker-less lines. Markers are specified as in matplotlib.
用线显示两个变量之间的关系以强调连续性。绘制带有一个分类变量的散点图,排列点以显示值的分布。
`style_order`:list, optional
> Specified order for appearance of the `style` variable levels otherwise they are determined from the data. Not relevant when the `style` variable is numeric.
`{x,y}_bins`:lists or arrays or functions
> _Currently non-functional._
`units`:{long_form_var}
> Grouping variable identifying sampling units. When used, a separate line will be drawn for each unit with appropriate semantics, but no legend entry will be added. Useful for showing distribution of experimental replicates when exact identities are not needed.
>
> _Currently non-functional._
`estimator`:name of pandas method or callable or None, optional
> Method for aggregating across multiple observations of the `y` variable at the same `x` level. If `None`, all observations will be drawn. _Currently non-functional._
`ci`:int or “sd” or None, optional
> Size of the confidence interval to draw when aggregating with an estimator. “sd” means to draw the standard deviation of the data. Setting to `None` will skip bootstrapping. _Currently non-functional._
`n_boot`:int, optional
> Number of bootstraps to use for computing the confidence interval. _Currently non-functional._
`alpha`:float
> Proportional opacity of the points.
`{x,y}_jitter`:booleans or floats
> _Currently non-functional._
`legend`:“brief”, “full”, or False, optional
> How to draw the legend. If “brief”, numeric `hue` and `size` variables will be represented with a sample of evenly spaced values. If “full”, every group will get an entry in the legend. If `False`, no legend data is added and no legend is drawn.
`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 down to `plt.scatter` at draw time.
返回值:`ax`:matplotlib Axes
> Returns the Axes object with the plot drawn onto it.
See also
Show the relationship between two variables connected with lines to emphasize continuity.Draw a scatter plot with one categorical variable, arranging the points to show the distribution of values.
Examples
Draw a simple scatter plot between two variables:
```py
>>> import seaborn as sns; sns.set()
>>> import matplotlib.pyplot as plt
>>> tips = sns.load_dataset("tips")
>>> ax = sns.scatterplot(x="total_bill", y="tip", data=tips)
例子
绘制一个两个变量的简单散点图:
```python
import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
tips = sns.load_dataset('tips')
ax = sns.scatterplot(x='total_bill',y='tip',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard1.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-1.png](img/0c0c7dd9c7bdb6a6490d4f09db142ec7.jpg)
Group by another variable and show the groups with different colors:
```py
>>> ax = sns.scatterplot(x="total_bill", y="tip", hue="time",
... data=tips)
通过其他的变量分组并且用不同的颜色展示分组
```python
ax = sns.scatterplot(x='total_bill',y='tip',hue='time',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard2.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-2.png](img/7fa2188b7e7f18a4af451121d39996f0.jpg)
Show the grouping variable by varying both color and marker:
```py
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="time", style="time", data=tips)
通过不同的颜色和标记显示分组变量:
```python
ax = sns.scatterplot(x='total_bill',y='tip',
hue='time',style='time',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard3.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-3.png](img/efc3bf2e49e981db42de96bfa2fbf3c3.jpg)
Vary colors and markers to show two different grouping variables:
```py
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="day", style="time", data=tips)
不同的颜色和标志显示两个不同的分组变量:
```python
ax = sns.scatterplot(x='total_bill',y='tip',
hue='day',style='time',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard4.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-4.png](img/9cd2a9e38e483ecbe02a7f0d0b67aac3.jpg)
Show a quantitative variable by varying the size of the points:
```py
>>> ax = sns.scatterplot(x="total_bill", y="tip", size="size",
... data=tips)
用不同大小的点显示一个变量的数量:
```python
ax = sns.scatterplot(x='total_bill',y='tip', size='size',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard5.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-5.png](img/eed42ab8c9334459069ea90987d5a184.jpg)
Also show the quantitative variable by also using continuous colors:
```py
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... data=tips)
使用渐变的颜色显示变量的数量:
```python
ax = sns.scatterplot(x='total_bill',y='tip',
hue='size', size='size',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard6.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-6.png](img/2777268c97b2e7b9d1e8269eb5a30c32.jpg)
Use a different continuous color map:
```py
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... palette=cmap,
... data=tips)
用一个不一样的渐变颜色映射:
```python
cmap = sns.cubehelix_palette(dark=.3,light=.8,as_cmap=True)
ax = sns.scatterplot(x='total_bill',y='tip',
hue='size', size='size',palette=cmap,data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard7.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-7.png](img/6254a35c0308633b36668290c5aecadd.jpg)
Change the minimum and maximum point size and show all sizes in legend:
```py
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... sizes=(20, 200), palette=cmap,
... legend="full", data=tips)
改变点大小的最小值和最大值并在图例中显示所有的尺寸:
```python
cmap = sns.cubehelix_palette(dark=.3,light=.8,as_cmap=True)
ax = sns.scatterplot(x='total_bill',y='tip',
hue='size',size='size', sizes=(20,200),legend='full',palette=cmap,data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard8.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-8.png](img/8dce33a113d5097dca0507c737d018d4.jpg)
Use a narrower range of color map intensities:
```py
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="size", size="size",
... sizes=(20, 200), hue_norm=(0, 7),
... legend="full", data=tips)
使用一个更小的颜色强度范围:
```python
cmap = sns.cubehelix_palette(dark=.3,light=.8,as_cmap=True)
ax = sns.scatterplot(x='total_bill',y='tip',hue='size',size='size',
sizes=(20,200),hue_norm=(0,7), legend='full',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard9.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-9.png](img/83eadbdb8a87de2c9615c02d627bb299.jpg)
Vary the size with a categorical variable, and use a different palette:
```py
>>> cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... hue="day", size="smoker",
... palette="Set2",
... data=tips)
一个类别变量不同的大小,用不同的颜色:
```python
ax = sns.scatterplot(x='total_bill',y='tip',hue='day',size='smoker',
palette='Set2',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard10.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-10.png](img/a5b1731f0fcd91611390c0bb109cfe64.jpg)
Use a specific set of markers:
```py
>>> markers = {"Lunch": "s", "Dinner": "X"}
>>> ax = sns.scatterplot(x="total_bill", y="tip", style="time",
... markers=markers,
... data=tips)
使用一些特定的标识:
```python
markers = {'Lunch':'s','Dinner':'X'}
ax = sns.scatterplot(x='total_bill',y='tip',style='time',
markers=markers,data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard11.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-11.png](img/d36b6251be5569fe2c31daea7543bf8a.jpg)
Control plot attributes using matplotlib parameters:
```py
>>> ax = sns.scatterplot(x="total_bill", y="tip",
... s=100, color=".2", marker="+",
... data=tips)
使用matplotlib的参数控制绘制属性:
```python
ax = sns.scatterplot(x='total_bill',y='tip',
s=100,color='.2',marker='+',data=tips)
```
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard12.png)
![http://seaborn.pydata.org/_images/seaborn-scatterplot-12.png](img/6096554e5a6fc5659cb1506870489993.jpg)
Pass data vectors instead of names in a data frame:
```py
>>> iris = sns.load_dataset("iris")
>>> ax = sns.scatterplot(x=iris.sepal_length, y=iris.sepal_width,
... hue=iris.species, style=iris.species)
使用data向量代替data frame名字:
```python
iris = sns.load_dataset('iris')
ax = sns.scatterplot(x=iris.sepal_length,y=iris.sepal_width,
hue = iris.species,style=iris.species)
```
![http://seaborn.pydata.org/_images/seaborn-scatterplot-13.png](img/5efb6c24bde137217b7d6471bd9e806a.jpg)
Pass a wide-form dataset and plot against its index:
```py
>>> import numpy as np, pandas as pd; plt.close("all")
>>> index = pd.date_range("1 1 2000", periods=100,
... freq="m", name="date")
>>> data = np.random.randn(100, 4).cumsum(axis=0)
>>> wide_df = pd.DataFrame(data, index, ["a", "b", "c", "d"])
>>> ax = sns.scatterplot(data=wide_df)
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard13.png)
传递宽格式数据并根据其索引进行绘图:
```python
import numpy as np, pandas as pd; plt.close("all")
index = pd.date_range('1 1 2000',periods=100,freq='m',name='date')
data = np.random.randn(100,4).cumsum(axis=0)
wide_df = pd.DataFrame(data,index,['a','b','c','d'])
print(wide_df.head())
ax = sns.scatterplot(data=wide_df)
```
![http://seaborn.pydata.org/_images/seaborn-scatterplot-14.png](img/ef47abe0a6cdede1f181c16d59bd3fe0.jpg)
\ No newline at end of file
![](https://raw.githubusercontent.com/leijuzi/img_seaborn_11/master/img_11/clipboard14.png)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册