python - 沿 x 轴在所需距离处的 seaborn 箱线图

标签 python pandas seaborn

有没有办法将 seaborn 箱线图沿 x 轴放置在所需的距离处?

我有一个数据框 具有索引分配、最大值、类型的分层列索引 学生姓名的行索引

+------------+----------+---------+----------+---------------+
| Type       | Homework | Quiz    | Homework | Presentations |
|            | max 100  | max 100 | max 100  | max 100       |
+------------+----------+---------+----------+---------------+
| Assignment | 1        | 2       | 3        | 4             |
+------------+----------+---------+----------+---------------+
| Student 1  | 88       | 98      | 100      | 85            |
+------------+----------+---------+----------+---------------+
| Student 2  | 96       | 79      | 100      | 97            |
+------------+----------+---------+----------+---------------+
| Student 3  | 87       | 79      | 72       | 78            |
+------------+----------+---------+----------+---------------+
| Student 4  | 87       | 84      | 90       | 85            |
+------------+----------+---------+----------+---------------+
| Student 5  | 73       | 91      | 76       | 90            |
+------------+----------+---------+----------+---------------+
| Student 6  | 70       | 75      | 98       | 82            |
+------------+----------+---------+----------+---------------+
| Student 7  | 85       | 71      | 73       | 75            |
+------------+----------+---------+----------+---------------+
| Student 8  | 76       | 81      | 94       | 86            |
+------------+----------+---------+----------+---------------+
| Student 9  | 97       | 80      | 95       | 88            |
+------------+----------+---------+----------+---------------+

实际上,分配是字符串并且更具描述性。

我可以轻松地将数据框输入 seaborn,它会生成一个漂亮的箱线图 sns.箱线图(df)

我真正想要的是将框分隔到不同的子图中(不难),但要按时间顺序适当间隔。

更清楚:

目前 sns.boxplot(df) 按时间顺序放置所有箱线图,这很好。 例如,我想要它上面的一个子图,它只有测验箱图,但测验箱图在 x 轴上水平排列,如果包括所有作业,它们将落在 x 轴上。

有没有办法将 seaborn 箱线图放置在 x 轴所需的距离处

sns.boxplot(df['Quiz'], x=[1,5,9,12]) 不起作用,因为您无法覆盖 x“值”(但这些只是标签)。

最佳答案

import numpy as np
import pandas as pd
import seaborn as sns
df = pd.DataFrame(dict(x=np.repeat([0, 3, 5, 6], 10),
                       y=np.random.randn(40)))
sns.boxplot(x="x", y="y", data=df, order=np.arange(7))

enter image description here

关于python - 沿 x 轴在所需距离处的 seaborn 箱线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35090425/

相关文章:

python - 如何用python在windows中打开文件?

python - blender Python MySQL

python - Pandas 聚合计数不同

python - Matplotlib 不听字体选择

python - 更改seaborn分布线的颜色

python - 提高 python dblquad 和多处理的速度

python - 对 Google Cloud Vision API 的多线程 python 调用

python - 为什么 `head` 需要 `()` 而 `shape` 不需要?

python - 检查 Pandas 列列表中的项目是否包含另一列中的值

python - 我可以将字典的值分成多列并且仍然能够绘制它们吗?