未验证 提交 2f1aace5 编写于 作者: 飞龙 提交者: GitHub

Merge pull request #17 from hold2010/translate

Translate
# Plotting with categorical data
# 可视化分类数据
In the [relational plot tutorial](relational.html#relational-tutorial) we saw how to use different visual representations to show the relationship between multiple variables in a dataset. In the examples, we focused on cases where the main relationship was between two numerical variables. If one of the main variables is “categorical” (divided into discrete groups) it may be helpful to use a more specialized approach to visualization.
[绘制关系图](relational.html#relational-tutorial)的教程中,我们学习了如何使用不同的可视化方法来展示数据集中多个变量之间的关系。在示例中,我们专注于两个数值变量之间的主要关系。如果其中一个主要变量是“可分类的”(能被分为不同的组),那么我们可以使用更专业的可视化方法。
In seaborn, there are several different ways to visualize a relationship involving categorical data. Similar to the relationship between [`relplot()`](../generated/seaborn.relplot.html#seaborn.relplot "seaborn.relplot") and either [`scatterplot()`](../generated/seaborn.scatterplot.html#seaborn.scatterplot "seaborn.scatterplot") or [`lineplot()`](../generated/seaborn.lineplot.html#seaborn.lineplot "seaborn.lineplot"), there are two ways to make these plots. There are a number of axes-level functions for plotting categorical data in different ways and a figure-level interface, [`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot"), that gives unified higher-level access to them.
在seaborn中,有几种不同的方法可以对分类数据进行可视化。类似于[`relplot()`](../generated/seaborn.relplot.html#seaborn.relplot "seaborn.relplot")[`scatterplot()`](../generated/seaborn.scatterplot.html#seaborn.scatterplot "seaborn.scatterplot")或者[`lineplot()`](../generated/seaborn.lineplot.html#seaborn.lineplot "seaborn.lineplot")之间的关系,有两种方法可以制作这些图。有许多axes-level函数可以用不同的方式绘制分类数据,还有一个figure-level接口[`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot"),可以对它们进行统一的高级访问。
It’s helpful to think of the different categorical plot kinds as belonging to three different families, which we’ll discuss in detail below. They are:
将不同的分类图类型视为三个不同的家族,这是很有帮助的。下面我们将详细讨论,它们是:
Categorical scatterplots:
分类散点图:
* [`stripplot()`](../generated/seaborn.stripplot.html#seaborn.stripplot "seaborn.stripplot") (with `kind="strip"`; the default)
* [`swarmplot()`](../generated/seaborn.swarmplot.html#seaborn.swarmplot "seaborn.swarmplot") (with `kind="swarm"`)
Categorical distribution plots:
分类分布图:
* [`boxplot()`](../generated/seaborn.boxplot.html#seaborn.boxplot "seaborn.boxplot") (with `kind="box"`)
* [`violinplot()`](../generated/seaborn.violinplot.html#seaborn.violinplot "seaborn.violinplot") (with `kind="violin"`)
* [`boxenplot()`](../generated/seaborn.boxenplot.html#seaborn.boxenplot "seaborn.boxenplot") (with `kind="boxen"`)
Categorical estimate plots:
分类估计图:
* [`pointplot()`](../generated/seaborn.pointplot.html#seaborn.pointplot "seaborn.pointplot") (with `kind="point"`)
* [`barplot()`](../generated/seaborn.barplot.html#seaborn.barplot "seaborn.barplot") (with `kind="bar"`)
* [`countplot()`](../generated/seaborn.countplot.html#seaborn.countplot "seaborn.countplot") (with `kind="count"`)
These families represent the data using different levels of granularity. When knowing which to use, you’ll have to think about the question that you want to answer. The unified API makes it easy to switch between different kinds and see your data from several perspectives.
这些家族使用不同的粒度级别来表示数据,我们应该根据实际情况来决定到底要使用哪个。它们有统一的API,所以我们可以轻松地在不同类型之间进行切换,并从多个角度来观察数据。
In this tutorial, we’ll mostly focus on the figure-level interface, [`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot"). Remember that this function is a higher-level interface each of the functions above, so we’ll reference them when we show each kind of plot, keeping the more verbose kind-specific API documentation at hand.
在本教程中,我们主要关注figure-level接口[`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot")。这个函数是上述每个函数更高级别的接口,因此当我们显示每种绘图时都会引用它们,不清楚的话可以随时查看特定类型的API文档。
```py
import seaborn as sns
......@@ -34,9 +34,9 @@ sns.set(style="ticks", color_codes=True)
```
## Categorical scatterplots
## 分类散点图
The default representation of the data in [`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot") uses a scatterplot. There are actually two different categorical scatter plots in seaborn. They take different approaches to resolving the main challenge in representing categorical data with a scatter plot, which is that all of the points belonging to one category would fall on the same position along the axis corresponding to the categorical variable. The approach used by [`stripplot()`](../generated/seaborn.stripplot.html#seaborn.stripplot "seaborn.stripplot"), which is the default “kind” in [`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot") is to adjust the positions of points on the categorical axis with a small amount of random “jitter”:
[`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot")中,数据默认使用散点图表示。在seaborn中有两种不同的分类散点图,它们采用不同的方法来表示分类数据。 其中一种是属于一个类别的所有点,将沿着与分类变量对应的轴落在相同位置。[`stripplot()`](../generated/seaborn.stripplot.html#seaborn.stripplot "seaborn.stripplot")方法是[`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot")中kind的默认参数,它是用少量随机“抖动”调整分类轴上的点的位置:
```py
tips = sns.load_dataset("tips")
......@@ -46,7 +46,7 @@ sns.catplot(x="day", y="total_bill", data=tips);
![http://seaborn.pydata.org/_images/categorical_4_0.png](img/8b6d8073c4f09f7584b0ff62e5d28d0d.jpg)
The `jitter` parameter controls the magnitude of jitter or disables it altogether:
`jitter`参数控制抖动的大小,你也可以完全禁用它:
```py
sns.catplot(x="day", y="total_bill", jitter=False, data=tips);
......@@ -55,7 +55,7 @@ sns.catplot(x="day", y="total_bill", jitter=False, data=tips);
![http://seaborn.pydata.org/_images/categorical_6_0.png](img/69f7923f9645a5a6bd0152889dc41109.jpg)
The second approach adjusts the points along the categorical axis using an algorithm that prevents them from overlapping. It can give a better representation of the distribution of observations, although it only works well for relatively small datasets. This kind of plot is sometimes called a “beeswarm” and is drawn in seaborn by [`swarmplot()`](../generated/seaborn.swarmplot.html#seaborn.swarmplot "seaborn.swarmplot"), which is activated by setting `kind="swarm"` in [`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot"):
另一种方法使用防止它们重叠的算法沿着分类轴调整点。我们可以用它更好地表示观测分布,但是只适用于相对较小的数据集。这种绘图有时被称为“beeswarm”,可以使用seaborn中的[`swarmplot()`](../generated/seaborn.swarmplot.html#seaborn.swarmplot "seaborn.swarmplot")绘制,通过在[`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot")中设置`kind="swarm"`来激活:
```py
sns.catplot(x="day", y="total_bill", kind="swarm", data=tips);
......@@ -64,7 +64,7 @@ sns.catplot(x="day", y="total_bill", kind="swarm", data=tips);
![http://seaborn.pydata.org/_images/categorical_8_0.png](img/6f14991596118430a71f67d61d84933e.jpg)
Similar to the relational plots, it’s possible to add another dimension to a categorical plot by using a `hue` semantic. (The categorical plots do not currently support `size` or `style` semantics). Each different categorical plotting function handles the `hue` semantic differently. For the scatter plots, it is only necessary to change the color of the points:
与关系图类似,可以通过使用`hue`语义向分类图添加另一个维。(分类图当前不支持`size``style`语义 )。 每个不同的分类绘图函数以不同方式处理`hue` 语义。对于散点图,我们只需要更改点的颜色:
```py
sns.catplot(x="day", y="total_bill", hue="sex", kind="swarm", data=tips);
......@@ -73,7 +73,7 @@ sns.catplot(x="day", y="total_bill", hue="sex", kind="swarm", data=tips);
![http://seaborn.pydata.org/_images/categorical_10_0.png](img/5ad59a428adab872b085f94007435de3.jpg)
Unlike with numerical data, it is not always obvious how to order the levels of the categorical variable along its axis. In general, the seaborn categorical plotting functions try to infer the order of categories from the data. If your data have a pandas `Categorical` datatype, then the default order of the categories can be set there. If the variable passed to the categorical axis looks numerical, the levels will be sorted. But the data are still treated as categorical and drawn at ordinal positions on the categorical axes (specifically, at 0, 1, …) even when numbers are used to label them:
与数值数据不同,如何沿着轴顺序排列分类变量并不总是显而易见的。通常,seaborn分类绘图函数试图从数据中推断出类别的顺序。 如果您的数据具有pandas中的`Categorical`数据类型,则可以在此处设置类别的默认顺序。如果传递给分类轴的变量看起来是数字,则将对级别进行排序。但是数据仍然被视为分类并在分类轴上的序数位置(特别是0,1,......)处理,即使用数字来标记它们:
```py
sns.catplot(x="size", y="total_bill", kind="swarm",
......@@ -83,8 +83,7 @@ sns.catplot(x="size", y="total_bill", kind="swarm",
![http://seaborn.pydata.org/_images/categorical_12_0.png](img/0dc6d842f7d01eca73fa0b7426a6d152.jpg)
The other option for chosing a default ordering is to take the levels of the category as they appear in the dataset. The ordering can also be controlled on a plot-specific basis using the `order` parameter. This can be important when drawing multiple categorical plots in the same figure, which we’ll see more of below:
选择默认排序的另一个选项是获取数据集中出现的类别级别。也可以使用`order`参数在特定图表的基础上控制排序。在同一图中绘制多个分类图时,这很重要,我们将在下面看到更多:
```py
sns.catplot(x="smoker", y="tip", order=["No", "Yes"], data=tips);
......@@ -92,7 +91,7 @@ sns.catplot(x="smoker", y="tip", order=["No", "Yes"], data=tips);
![http://seaborn.pydata.org/_images/categorical_14_0.png](img/ff513e6aaa65c95e4855ad207cee0757.jpg)
We’ve referred to the idea of “categorical axis”. In these examples, that’s always corresponded to the horizontal axis. But it’s often helpful to put the categorical variable on the vertical axis (particularly when the category names are relatively long or there are many categories). To do this, swap the assignment of variables to axes:
我们已经提到了“分类轴”的概念。在这些示例中,它始终对应于水平轴。但是将分类变量放在垂直轴上通常很有帮助(特别是当类别名称相对较长或有许多类别时)。为此,我们交换轴上的变量赋值:
```py
sns.catplot(x="total_bill", y="day", hue="time", kind="swarm", data=tips);
......@@ -101,13 +100,13 @@ sns.catplot(x="total_bill", y="day", hue="time", kind="swarm", data=tips);
![http://seaborn.pydata.org/_images/categorical_16_0.png](img/8755b1ae3c5d3d74addc89c78230b77c.jpg)
## Distributions of observations within categories
## 类别内观察点的分布
As the size of the dataset grows,, categorical scatter plots become limited in the information they can provide about the distribution of values within each category. When this happens, there are several approaches for summarizing the distributional information in ways that facilitate easy comparisons across the category levels.
随着数据集的大小增加,分类散点图中每个类别可以提供的值分布信息受到限制。当发生这种情况时,有几种方法可以总结分布信息,以便于我们可以跨分类级别进行简单比较。
### Boxplots
### 箱线图
The first is the familiar [`boxplot()`](../generated/seaborn.boxplot.html#seaborn.boxplot "seaborn.boxplot"). This kind of plot shows the three quartile values of the distribution along with extreme values. The “whiskers” extend to points that lie within 1.5 IQRs of the lower and upper quartile, and then observations that fall outside this range are displayed independently. This means that each value in the boxplot corresponds to an actual observation in the data.
第一个是熟悉的[`boxplot()`](../generated/seaborn.boxplot.html#seaborn.boxplot "seaborn.boxplot")。它可以显示分布的三个四分位数值以及极值。“胡须”延伸到位于下四分位数和上四分位数的1.5 IQR内的点,超出此范围的观察值会独立显示。这意味着箱线图中的每个值对应于数据中的实际观察值。
```py
sns.catplot(x="day", y="total_bill", kind="box", data=tips);
......@@ -116,8 +115,7 @@ sns.catplot(x="day", y="total_bill", kind="box", data=tips);
![http://seaborn.pydata.org/_images/categorical_18_0.png](img/808e3bf946312498595c712d13d5401a.jpg)
When adding a `hue` semantic, the box for each level of the semantic variable is moved along the categorical axis so they don’t overlap:
添加`hue`语义, 语义变量的每个级别的框沿着分类轴移动,因此它们将不会重叠:
```py
sns.catplot(x="day", y="total_bill", hue="smoker", kind="box", data=tips);
......@@ -125,7 +123,7 @@ sns.catplot(x="day", y="total_bill", hue="smoker", kind="box", data=tips);
![http://seaborn.pydata.org/_images/categorical_20_0.png](img/1f4ad95dbd00806b549ece0b87386cf9.jpg)
This behavior is called “dodging” and is turned on by default because it is assumed that the semantic variable is nested within the main categorical variable. If that’s not the case, you can disable the dodging:
此行为被称为“dodging”,默认开启,因为我们假定语义变量嵌套在主分类变量中。如果不是这样,可以禁用dodging:
```py
tips["weekend"] = tips["day"].isin(["Sat", "Sun"])
......@@ -136,7 +134,7 @@ sns.catplot(x="day", y="total_bill", hue="weekend",
![http://seaborn.pydata.org/_images/categorical_22_0.png](img/3690d2883f41b811443d3bfd92e7a9d7.jpg)
A related function, [`boxenplot()`](../generated/seaborn.boxenplot.html#seaborn.boxenplot "seaborn.boxenplot"), draws a plot that is similar to a box plot but optimized for showing more information about the shape of the distribution. It is best suited for larger datasets:
一个相关的函数[`boxenplot()`](../generated/seaborn.boxenplot.html#seaborn.boxenplot "seaborn.boxenplot")可以绘制一个与Box-plot类似的图。它为了显示更多信息而对分布的形状进行了优化,比较适合于较大的数据集:
```py
diamonds = sns.load_dataset("diamonds")
......@@ -147,9 +145,9 @@ sns.catplot(x="color", y="price", kind="boxen",
![http://seaborn.pydata.org/_images/categorical_24_0.png](img/79a1d5cfd5409b9ac27b12fa7ec657d6.jpg)
### Violinplots
### 小提琴图
A different approach is a [`violinplot()`](../generated/seaborn.violinplot.html#seaborn.violinplot "seaborn.violinplot"), which combines a boxplot with the kernel density estimation procedure described in the [distributions](distributions.html#distribution-tutorial) tutorial:
另一种方法是[`violinplot()`](../generated/seaborn.violinplot.html#seaborn.violinplot "seaborn.violinplot"),它将箱线图与[分布](distributions.html#distribution-tutorial)教程中描述的核密度估算程序结合起来:
```py
sns.catplot(x="total_bill", y="day", hue="time",
......@@ -159,7 +157,7 @@ sns.catplot(x="total_bill", y="day", hue="time",
![http://seaborn.pydata.org/_images/categorical_26_0.png](img/d9dc602fc56dec13039df115c589dd05.jpg)
This approach uses the kernel density estimate to provide a richer description of the distribution of values. Additionally, the quartile and whikser values from the boxplot are shown inside the violin. The downside is that, because the violinplot uses a KDE, there are some other parameters that may need tweaking, adding some complexity relative to the straightforward boxplot:
该方法使用核密度估计来提供更丰富的值分布描述。此外,violin中还显示了来自箱线图的四分位数和whikser值。缺点是由于violinplot使用了KDE,我们需要调整一些额外参数,与箱形图相比增加了一些复杂性:
```py
sns.catplot(x="total_bill", y="day", hue="time",
......@@ -170,7 +168,7 @@ sns.catplot(x="total_bill", y="day", hue="time",
![http://seaborn.pydata.org/_images/categorical_28_0.png](img/93d6927062ff93035052ed79d6e8e224.jpg)
It’s also possible to “split” the violins when the hue parameter has only two levels, which can allow for a more efficient use of space:
当hue参数只有两个级别时,也可以“拆分”violins,这样可以更有效地利用空间:
```py
sns.catplot(x="day", y="total_bill", hue="sex",
......@@ -180,7 +178,7 @@ sns.catplot(x="day", y="total_bill", hue="sex",
![http://seaborn.pydata.org/_images/categorical_30_0.png](img/a450fb151022958086f1733274e4f66b.jpg)
Finally, there are several options for the plot that is drawn on the interior of the violins, including ways to show each individual observation instead of the summary boxplot values:
最后,在violin内的绘图有几种选项,包括显示每个独立的观察而不是摘要箱线图值的方法:
```py
sns.catplot(x="day", y="total_bill", hue="sex",
......@@ -191,7 +189,7 @@ sns.catplot(x="day", y="total_bill", hue="sex",
![http://seaborn.pydata.org/_images/categorical_32_0.png](img/a1fee05f41f1d43a9d9a6f1b9c301e0d.jpg)
It can also be useful to combine [`swarmplot()`](../generated/seaborn.swarmplot.html#seaborn.swarmplot "seaborn.swarmplot") or `striplot()` with a box plot or violin plot to show each observation along with a summary of the distribution:
我们也可以将[`swarmplot()`](../generated/seaborn.swarmplot.html#seaborn.swarmplot "seaborn.swarmplot")`striplot()`与箱形图或violin plot结合起来,展示每次观察以及分布摘要:
```py
g = sns.catplot(x="day", y="total_bill", kind="violin", inner=None, data=tips)
......@@ -201,13 +199,13 @@ sns.swarmplot(x="day", y="total_bill", color="k", size=3, data=tips, ax=g.ax);
![http://seaborn.pydata.org/_images/categorical_34_0.png](img/26ac3dbbb98ec93352f776de6e6d2b65.jpg)
## Statistical estimation within categories
## 类别内的统计估计
For other applications, rather than showing the distribution within each category, you might want to show an estimate of the central tendency of the values. Seaborn has two main ways to show this information. Importantly, the basic API for these functions is identical to that for the ones discussed above.
对于其他应用程序,你可能希望显示值的集中趋势估计,而不是显示每个类别中的分布。Seaborn有两种主要方式来显示这些信息。重要的是,这些功能的基本API与上面讨论的API相同。
### Bar plots
### 条形图
A familiar style of plot that accomplishes this goal is a bar plot. In seaborn, the [`barplot()`](../generated/seaborn.barplot.html#seaborn.barplot "seaborn.barplot") function operates on a full dataset and applies a function to obtain the estimate (taking the mean by default). When there are multiple observations in each category, it also uses bootstrapping to compute a confidence interval around the estimate and plots that using error bars:
实现这一目标的是我们熟悉的条形图。在seaborn中,[`barplot()`](../generated/seaborn.barplot.html#seaborn.barplot "seaborn.barplot")函数在完整数据集上运行并应用函数来获取估计值(默认情况下取平均值)。当每个类别中有多个观察值时,它还使用自举来计算估计值周围的置信区间,并使用误差条绘制:
```py
titanic = sns.load_dataset("titanic")
......@@ -217,7 +215,7 @@ sns.catplot(x="sex", y="survived", hue="class", kind="bar", data=titanic);
![http://seaborn.pydata.org/_images/categorical_36_0.png](img/727bcad15c428cfdd74d27db87677157.jpg)
A special case for the bar plot is when you want to show the number of observations in each category rather than computing a statistic for a second variable. This is similar to a histogram over a categorical, rather than quantitative, variable. In seaborn, it’s easy to do so with the [`countplot()`](../generated/seaborn.countplot.html#seaborn.countplot "seaborn.countplot") function:
条形图的一个特例是,当你想要显示每个类别中的观察数量而不是计算第二个变量的统计数据时。这类似于分类而非定量变量的直方图。在seaborn中,使用[`countplot()`](../generated/seaborn.countplot.html#seaborn.countplot "seaborn.countplot")函数很容易实现:
```py
sns.catplot(x="deck", kind="count", palette="ch:.25", data=titanic);
......@@ -226,7 +224,7 @@ sns.catplot(x="deck", kind="count", palette="ch:.25", data=titanic);
![http://seaborn.pydata.org/_images/categorical_38_0.png](img/9788e48ccbd895c1e539c7de634be115.jpg)
Both [`barplot()`](../generated/seaborn.barplot.html#seaborn.barplot "seaborn.barplot") and [`countplot()`](../generated/seaborn.countplot.html#seaborn.countplot "seaborn.countplot") can be invoked with all of the options discussed above, along with others that are demonstrated in the detailed documentation for each function:
无论是[`barplot()`](../generated/seaborn.barplot.html#seaborn.barplot "seaborn.barplot")还是[`countplot()`](../generated/seaborn.countplot.html#seaborn.countplot "seaborn.countplot"),都可以使用上面讨论的所有选项,也可以调用每个函数的文档示例中的其他选项:
```py
sns.catplot(y="deck", hue="class", kind="count",
......@@ -237,9 +235,9 @@ sns.catplot(y="deck", hue="class", kind="count",
![http://seaborn.pydata.org/_images/categorical_40_0.png](img/642ca1bac62921f4290064ab256538bb.jpg)
### Point plots
### 点图
An alternative style for visualizing the same information is offered by the [`pointplot()`](../generated/seaborn.pointplot.html#seaborn.pointplot "seaborn.pointplot") function. This function also encodes the value of the estimate with height on the other axis, but rather than showing a full bar, it plots the point estimate and confidence interval. Additionally, [`pointplot()`](../generated/seaborn.pointplot.html#seaborn.pointplot "seaborn.pointplot") connects points from the same `hue` category. This makes it easy to see how the main relationship is changing as a function of the hue semantic, because your eyes are quite good at picking up on differences of slopes:
[`pointplot()`](../generated/seaborn.pointplot.html#seaborn.pointplot "seaborn.pointplot")函数提供了另一种可视化相同信息的样式。此函数还对另一个轴上的高度估计值进行编码,但不是显示一个完整的条形图,而是绘制点估计值和置信区间。另外,[`pointplot()`](../generated/seaborn.pointplot.html#seaborn.pointplot "seaborn.pointplot")连接来自相同`hue`类别的点。我们可以很容易的看出主要关系如何随着色调语义的变化而变化,因为人类的眼睛很擅长观察斜率的差异:
```py
sns.catplot(x="sex", y="survived", hue="class", kind="point", data=titanic);
......@@ -248,7 +246,7 @@ sns.catplot(x="sex", y="survived", hue="class", kind="point", data=titanic);
![http://seaborn.pydata.org/_images/categorical_42_0.png](img/687f85f5e0e06a68e6150c0533ff1748.jpg)
When the categorical functions lack the `style` semantic of the relational functions, it can still be a good idea to vary the marker and/or linestyle along with the hue to make figures that are maximally accessible and reproduce well in black and white:
当分类函数缺少关系函数中的`style`语义时, 将markers和linestyles与色调一起改变,以制作最大可访问的图形并在黑白中重现良好,这仍然是一个好主意:
```py
sns.catplot(x="class", y="survived", hue="sex",
......@@ -260,9 +258,9 @@ sns.catplot(x="class", y="survived", hue="sex",
![http://seaborn.pydata.org/_images/categorical_44_0.png](img/77fc98bcda361af76626399c4a1e7ad8.jpg)
## Plotting “wide-form” data
## 绘制“宽格式”数据
While using “long-form” or “tidy” data is preferred, these functions can also by applied to “wide-form” data in a variety of formats, including pandas DataFrames or two-dimensional numpy arrays. These objects should be passed directly to the `data` parameter:
虽然优选使用“长形式”或“整齐”数据,但这些函数也可以应用于各种“宽格式”的数据,包括pandas DataFrames或二维numpy数组。这些对象应该直接传递给`data`参数:
```py
iris = sns.load_dataset("iris")
......@@ -272,7 +270,7 @@ sns.catplot(data=iris, orient="h", kind="box");
![http://seaborn.pydata.org/_images/categorical_46_0.png](img/5307ba94c8d5a2ecca04c697414a762a.jpg)
Additionally, the axes-level functions accept vectors of Pandas or numpy objects rather than variables in a `DataFrame`:
另外,axes-level函数接受Pandas或numpy对象的向量,而不是`DataFrame`中的变量:
```py
sns.violinplot(x=iris.species, y=iris.sepal_length);
......@@ -281,7 +279,7 @@ sns.violinplot(x=iris.species, y=iris.sepal_length);
![http://seaborn.pydata.org/_images/categorical_48_0.png](img/426ace59c775cc095c6128e35bcff1b3.jpg)
To control the size and shape of plots made by the functions discussed above, you must set up the figure yourself using matplotlib commands:
要控制上面讨论的函数绘制的图形的大小和形状,你必须使用matplotlib命令来进行设置:
```py
f, ax = plt.subplots(figsize=(7, 3))
......@@ -291,11 +289,11 @@ sns.countplot(y="deck", data=titanic, color="c");
![http://seaborn.pydata.org/_images/categorical_50_0.png](img/b18371fc898cfe7904a1fc240f6fe4e8.jpg)
This is the approach you should take when you need a categorical figure to happily coexist in a more complex figure with other kinds of plots.
当你需要一个分类图与一个更复杂的其他类型的图共存时,你可以采取这种方法。
## Showing multiple relationships with facets
## 显示与facet的多种关系
Just like [`relplot()`](../generated/seaborn.relplot.html#seaborn.relplot "seaborn.relplot"), the fact that [`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot") is built on a [`FacetGrid`](../generated/seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") means that it is easy to add faceting variables to visualize higher-dimensional relationships:
就像[`relplot()`](../generated/seaborn.relplot.html#seaborn.relplot "seaborn.relplot")一样, [`catplot()`](../generated/seaborn.catplot.html#seaborn.catplot "seaborn.catplot")建立在[`FacetGrid`](../generated/seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")上,这意味着很容易添加层面变量来可视化高维关系:
```py
sns.catplot(x="day", y="total_bill", hue="smoker",
......@@ -306,7 +304,7 @@ sns.catplot(x="day", y="total_bill", hue="smoker",
![http://seaborn.pydata.org/_images/categorical_52_0.png](img/c8197cd6e74c99a9483c72ed6b43a01a.jpg)
For further customization of the plot, you can use the methods on the [`FacetGrid`](../generated/seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid") object that it returns:
要进一步自定义绘图,我们可以使用它返回的[`FacetGrid`](../generated/seaborn.FacetGrid.html#seaborn.FacetGrid "seaborn.FacetGrid")对象上的方法:
```py
g = sns.catplot(x="fare", y="survived", row="class",
......@@ -316,4 +314,4 @@ g.set(xscale="log");
```
![http://seaborn.pydata.org/_images/categorical_54_0.png](img/64c8d092f1c51150e58e0a41dfcad834.jpg)
\ No newline at end of file
![http://seaborn.pydata.org/_images/categorical_54_0.png](img/64c8d092f1c51150e58e0a41dfcad834.jpg)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册