Sea boxes at desired distances along the x axis

In any case, place square seaborn boxes at desired distances along the x axis?

I have a dataframe with a Hierarchical index column with indexes Purpose, Max., Type the index of the row 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 | +------------+----------+---------+----------+---------------+ 

Assignments are actually strings and more descriptive.

I can easily feed the dataframe to the marine environment and this will give a nice sns.boxplot (DF) plot

I would really like the boxes to be divided into different subheadings (not difficult), but that they be arranged in chronological order.

More clearly:

Currently, sns.boxplot(df) puts all timing charts in chronological order, which is nice. For example, I would like to add a subtitle above it, which had only quiz graphs, but the quiz window graphs are lined up horizontally along the x axis, where they will fall if all destinations are turned on.

In any case, place the sea crates at the required distances along the x axis ?

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

+5
source share
2 answers
 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

+7
source

Short answer: no, seaborn.boxplot not able to indicate the position of the boxes on the x axis.

If you don't like the style, or you can specify it manually, you can use pandas.DataFrame.boxplot instead, which has the positions property.

 import matplotlib.pyplot as plt import pandas as pd import numpy.random as rnd # just to generate some data data = pd.DataFrame(rnd.randn(10,4)) data.boxplot(positions=[1,5,6,10]) plt.grid('off') 

boxplot with positions

UPDATE . It seems I was wrong, because the mwaskom pointer indicated that you can specify positions using order , but it looks like you will need to change your data from β€œwide” to β€œlong”.

+2
source

Source: https://habr.com/ru/post/1241841/


All Articles