天天看点

seaborn_seaborn 0 11刚刚发布,具有许多新功能

seaborn

Seaborn is a high-level Python data visualization library built on Matplotlib. It makes it convenient to create many different informative statistical visualizations.

Seaborn是基于Matplotlib构建的高级Python数据可视化库。 它使创建许多不同的信息统计可视化变得很方便。

The new version (0.11.0) of Seaborn just released with new features and enhancements on the existing ones. In this post, we will cover most of the changes with sample visualizations.

Seaborn的新版本(0.11.0)刚刚发布,具有现有功能的新功能和增强功能。 在本文中,我们将通过示例可视化介绍大多数更改。

Three new functions have been introduced which are displot, histplot, and ecdfplot. These three functions can be used to visualize univariate or bivariate data distributions.

引入了三个新功能,分别是displot , histplot和ecdfplot。 这三个函数可用于可视化单变量或双变量数据分布。

Note: In order to use the new features, you need to update to the new version which can be done with

pip install seaborn==0.11.0

.

注意 :为了使用新功能,您需要更新到新版本,可以通过

pip install seaborn==0.11.0

来完成。

Let’s start with the distplot. It can be considered as the parent class of the other two. The distplot, using the kind parameter, provides access to histplot, ecdfplot, and kdeplot. Thus, it is a figure-level interface for different kinds of distribution plots.

让我们从distplot开始。 可以将其视为其他两个的父类。 使用kind参数的distplot提供对histplot,ecdfplot和kdeplot的访问。 因此,它是用于不同种类分布图的图形级界面。

Here is an example.

这是一个例子。

sns.displot(data=diabetes, x='Glucose', kind='hist', height=6, aspect=1.2)
           
seaborn_seaborn 0 11刚刚发布,具有许多新功能

We’ve plotted a histogram showing the univariate distribution of the glucose variable.

我们绘制了一个直方图,显示了葡萄糖变量的单变量分布。

The following code will create a histogram that shows the bivariate distribution of the glucose and blood pressure variables.

以下代码将创建一个直方图,该直方图显示葡萄糖和血压变量的双变量分布。

sns.displot(data=diabetes, x='Glucose', y='BloodPressure',
kind='hist', height=6, aspect=1.2)
           
seaborn_seaborn 0 11刚刚发布,具有许多新功能

The darkness of regions increases with the number of data points within that region.

区域的暗度随该区域内数据点的数量而增加。

The distplot is a figure-level function whereas the histplot is an axes-level function. The same plot can be created with the following syntax of histplot function.

distplot是图形级函数,而histplot是轴级函数。 可以使用histplot函数的以下语法创建相同的图。

sns.histplot(data=diabetes, x='Glucose', y='BloodPressure')
           

If you’d like to learn more about Figure and Axes concepts of Matplotlib, here is a detailed post about the structure of Matplotlib.

如果您想了解有关Matplotlib的Figure和Axes概念的更多信息, 这里是有关Matplotlib结构的详细文章。

Since displot draws figures on a FacetGrid, we can have multiple plots on the same figure.

由于displot借鉴了数字FacetGrid ,我们可以在同一个人物的多个地块。

sns.displot(data=churn, x='CreditScore', kind='hist',
col='Geography', hue='Exited')
           
seaborn_seaborn 0 11刚刚发布,具有许多新功能

The ecdfplot (Empirical Cumulative Distribution Functions) provides the proportion or count of observations falling below each unique value in a dataset. In addition to an overview of the distribution of variables, we get a more clear view of each observation in the data compared to a histogram because there is no binning (i.e. grouping).

ecdfplot(经验累积分布函数)提供低于数据集中每个唯一值的观测值的比例或计数。 除了概述变量的分布之外,与直方图相比,我们还可以更清楚地看到数据中的每个观察值,因为没有分类(即分组)。

sns.displot(data=churn, x='Age', kind='ecdf', col='Geography', hue='Exited')
           
seaborn_seaborn 0 11刚刚发布,具有许多新功能

The ecdfplot can only plot univariate distributions.

ecdfplot只能绘制单变量分布。

The new version comes with a depreciated function which is the distplot. It is kind of expected because the new functions (displot and histplot) seem to be better replacements for displot.

新版本带有折旧的函数distplot 。 可以预料,因为新功能(displot和histplot)似乎是Displot的更好替代品。

There are also improvements or enhancements on some of the currently used functions.

在某些当前使用的功能上也有改进或增强。

The jointplot provides univariate and bivariate plots of two variables. The hue semantic is added to jointplot which adds extra informative power.

联合图提供了两个变量的单变量和双变量图。 色调语义被添加到联合绘图中,从而增加了额外的信息功能。

sns.jointplot(data=diabetes, x='Insulin', y='BMI', hue='Outcome',
height=7)
           
seaborn_seaborn 0 11刚刚发布,具有许多新功能

Another addition to the jointplot is the “hist” option to the kind parameter. The default value of the kind parameter is “scatter” but if we change it as “hist”, bivariate histogram on the joint axes and univariate histograms on the marginal axes are created.

对关节图的另一个添加是kind参数的“ hist”选项。 kind参数的默认值为“ scatter”,但如果将其更改为“ hist”,则会在关节轴上创建双变量直方图,在边际轴上创建单变量直方图。

sns.jointplot(data=diabetes, x='Insulin', y='BMI', hue='Outcome',
kind='hist', height=7)
           
seaborn_seaborn 0 11刚刚发布,具有许多新功能

Some highlights about the API

有关API的一些要点

  • Set

    function has been renamed as

    set_theme

    . It adjusts several properties of the theme used in visualizations.

    Set

    函数已重命名为

    set_theme

    。 它调整了可视化中使用的主题的几个属性。
  • The

    axlabel

    function is no longer available. It is recommended to use

    ax.set(xlabel=, ylabel=)

    instead.

    axlabel

    函数不再可用。 建议使用

    ax.set(xlabel=, ylabel=)

    代替。

We have covered some of the major changes but if you’d like to see all the changes, here is the related seaborn documentation.

我们已经介绍了一些主要更改,但是如果您想查看所有更改,请参阅相关的seaborn 文档 。

If you’d like to practice yourself, you can access to the datasets on Kaggle.

如果您想练习,可以访问Kaggle上的数据集。

  • Diabetes

    糖尿病

  • Churn

    搅动

Thank you for reading. Please let me know if you have any feedback.

感谢您的阅读。 如果您有任何反馈意见,请告诉我。

翻译自: https://towardsdatascience.com/seaborn-0-11-just-released-with-great-new-features-c5b45efad7e2

seaborn