沿x轴以所需距离的海底箱形图 [英] seaborn boxplots at desired distances along the x axis

查看:59
本文介绍了沿x轴以所需距离的海底箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正沿x轴以所需距离放置seaborn箱形图了吗?

Is there anyway to place seaborn boxplots at desired distances along the x axis?

我有一个数据框 带有索引分配,最大值,类型的层次结构列索引 学生姓名的行索引

I've got a dataframe with hierarchical column index with indices Assignment, Max, Type a row index of student names

+------------+----------+---------+----------+---------------+
| 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            |
+------------+----------+---------+----------+---------------+

实际上,分配是字符串,更具描述性.

In reality the Assignments are strings and more descriptive.

我可以轻松地将数据框输入seaborn中,这将产生一个不错的箱形图 sns.boxplot(df)

I can easily feed the dataframe into seaborn and it will produce a nice box plot sns.boxplot(df)

我真正想要的是将盒子分成不同的子图(不难),但要按时间顺序适当地隔开.

What I'd really like is for the boxes to be separated onto different subplots (not hard), but to be spaced properly chronologically.

更清楚:

当前sns.boxplot(df)按时间顺序放置所有箱形图,这很好. 例如,我想在其上方创建一个子图,该子图只有测验框图,但是测验框图在x轴上水平排列,如果包括所有分配,它们将落在哪里.

Currently sns.boxplot(df) places all the box plots chronologically which is nice. I'd like a subplot above it, for example, which had only the quiz box plots, but the quiz box plots are lined up horizontally on the x axis with where they would fall if all the assignments were included.

反正有将海底箱形图沿x轴放置在所需距离吗?

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

sns.boxplot(df['Quiz'], x=[1,5,9,12]) DOES NOT work as you can't override the x 'values' (but these are just the labels).

推荐答案

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))

这篇关于沿x轴以所需距离的海底箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆