gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:31:36 24 4
gpt4 key购买 nike

有没有办法将 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com