当我只传递没有 x、y、数据参数的整个数据帧时,箱线图显示什么结果?

What results is the box plot showing when I just pass the entire dataframe with no x, y, data parameters?

我正在使用 python 库学习可视化。我正在玩弄内置的 "tips" 数据集。我注意到即使我没有提供任何参数,例如 x = 、 y= 、 data = ,seaborn 也会绘制数据。这是我试过的:

import pandas as pd
import seaborn as sns
tips_data = sns.load_dataset("tips")
tips_data.head()
sns.boxplot(tips_data.iloc[:,[0,1]])
sns.boxplot(data=tips_data.iloc[:,[0,1]])

如果你 运行 这些命令,你会注意到第一个箱线图命令绘制了一个箱线图,它与任何一列的箱线图、它们的平均值或它们的总和都不相同。

第二个箱形图命令正确,在同一轴上绘制了两个箱形图 - 一个用于提示,另一个用于 total_bill。

有人能告诉我在没有指定参数 arg 的情况下到底绘制了什么吗?

我尝试查看 seaborn 文档 here!但没有找到答案。

案例一

sns.boxplot(tips_data.iloc[:,[0,1]]) 等价于

sns.boxplot(x=tips_data.iloc[:,[0,1]])

即第一个参数是x。这被解释为输入中的所有数据都将沿 x 轴分布。更容易理解的是,这可能是来自两列的扁平化二维数组,

sns.boxplot(x=tips_data.iloc[:,[0,1]].values.flatten())

案例二

如果改为使用 sns.boxplot(data=tips_data.iloc[:,[0,1]]),则不会给出 xy。因此需要对它们进行解释,这是按列进行的。然后,您将获得每列一个箱线图。


文档指出:

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. [Case 1]
  • 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. [Case 2]

我在文档中标记了问题中的两个案例。