Draw a categorical scatterplot with non-overlapping points.
绘制具有非重叠点的分类散点图。
This function is similar to [`stripplot()`](seaborn.stripplot.html#seaborn.stripplot"seaborn.stripplot"), but the points are adjusted (only along the categorical axis) so that they don’t overlap. This gives a better representation of the distribution of values, but it does not scale well to large numbers of observations. This style of plot is sometimes called a “beeswarm”.
A swarm plot can be drawn on its own, but it is also a good complement to a box or violin plot in cases where you want to show all observations along with some representation of the underlying distribution.
Arranging the points properly requires an accurate transformation between data and point coordinates. This means that non-default axis limits must be set _before_ drawing the plot.
正确排列点需要在数据和点坐标之间进行精确转换。这意味着必须在绘制绘图之前设置非默认轴限制。
Input data can be passed in a variety of formats, including:
输入数据可以以多种格式传递,包括:
* 表示为列表,numpy arrays或pandas Series objects直接传递给`x`,`y`和/或`hue`参数。
* “长格式” DataFrame, `x`,`y`和`hue`变量将决定数据的绘制方式
* “宽格式”DataFrame,用于绘制每个数字列。
* 一个数组或向量列表。
* 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.
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.
> When using `hue` nesting, setting this to `True` will separate the strips for different hue levels along the categorical axis. Otherwise, the points for each level will be plotted in one swarm.
> 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, 可选
`color`:matplotlib color, optional
> 所有元素的颜色,或渐变调色板的种子。
> Color for all of the elements, or seed for a gradient palette.
> 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.
> Diameter of the markers, in points. (Although `plt.scatter` is used to draw the points, the `size` argument here takes a “normal” markersize and not size^2 like `plt.scatter`.
`edgecolor`:matplotlib color, “灰色”是特殊的,可选
`edgecolor`:matplotlib color, “gray” is special-cased, optional
> 每个点周围线条的颜色。如果传递`"gray"`,则亮度由用于点体的调色板决定。
> Color of the lines around each point. If you pass `"gray"`, the brightness is determined by the color palette used for the body of the points.
`linewidth`:float, 可选
`linewidth`:float, optional
> 构图元素的灰线宽度。
> Width of the gray lines that frame the plot elements.
`ax`:matplotlib Axes, 可选
`ax`:matplotlib Axes, optional
> Axes object to draw the plot onto, otherwise uses the current Axes.
> Axes对象将绘图绘制到,否则使用当前轴。
返回值:`ax`:matplotlib Axes
> Returns the Axes object with the plot drawn onto it.
> 返回Axes对象,并在其上绘制绘图。
See also
参看
A traditional box-and-whisker plot with a similar API.A combination of boxplot and kernel density estimation.A scatterplot where one variable is categorical. Can be used in conjunction with other plots to show each observation.Combine a categorical plot with a class:<cite>FacetGrid</cite>.
Use [`catplot()`](seaborn.catplot.html#seaborn.catplot"seaborn.catplot") to combine a [`swarmplot()`](#seaborn.swarmplot"seaborn.swarmplot") 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: