在 Seaborn 箱线图中获取值

Getting values in Seaborn boxplot

我想通过Seaborn生成的箱线图得到具体值 (即媒体、四分位数)。例如,在下面的箱线图中(来源:link) 有什么方法可以获取媒体和四分位数而不是手动估计吗?

import numpy as np
import seaborn as sns
sns.set(style="ticks", palette="muted", color_codes=True)

# Load the example planets dataset
planets = sns.load_dataset("planets")

# Plot the orbital period with horizontal boxes
ax = sns.boxplot(x="distance", y="method", data=planets,
             whis=np.inf, color="c")

我鼓励您熟悉使用 pandas 从数据框中提取定量信息。例如,您可以做一件简单的事情来获取您正在寻找的值(以及其他有用的值):

planets.groupby("method").distance.describe().unstack()

它为每个方法打印 table 个有用的值。

或者如果您只想要中位数:

planets.groupby("method").distance.median()

有时我将我的数据用作数组列表而不是 pandas。因此,为此,您可能需要:

min(d), np.quantile(d, 0.25), np.median(d), np.quantile(d, 0.75), max(d)