两列数据(垂直轴)与一列(水平轴)的箱线图

时间:2019-05-10 10:20:34

标签: python-3.x pandas jupyter seaborn boxplot

我试图绘制一个带有两个列变量(“ Sec”和“ pbl8”)的箱形图,而水平轴上的一个列名为“ FinalScore”。 我遇到的问题是箱形图重叠。我想在一个图中以名称命名的单独图。可以看到我不需要的前两个箱型图是重叠的。我想在同一图上分别显示它们。带有蓝点的箱线图在“ Sec”列(垂直轴)与“ FinalScore”列之间。其他图在“ pbl8”和“ FinalScore”列之间。我尝试了以下

boxplot of column 'pbl8' and 'Sec' against 'FinalScore'

import pandas as pd
import numpy as np
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt

test_df=df2[['Sec', 'pbl8', 'FinalScore']]

Sec pbl8    FinalScore
s10 s10g5   93.70
s10 s10g5   91.06
s10 s10g5   78.09
s10 s10g5   79.24
s10 s10g6   91.87
s10 s10g6   88.62
s10 s10g6   92.82
s10 s10g6   81.84
s10 s10g7   92.05
s10 s10g7   79.54
s10 s10g7   90.75
s10 s10g7   86.25
s10 s10g8   88.96
s10 s10g8   89.13
s10 s10g8   81.48
s10 s10g8   89.28
s10 s10g8   81.51

plt.figure(figsize=(10, 8), dpi=80)

bp=sns.pointplot(test_df['FinalScore'].mean(), color='b', markers='x', 
scale=1.2, capsize=0.15)
bp=sns.boxplot(test_df['FinalScore'], width=0.8, palette="cool", 
linewidth=1)
bp=sns.stripplot(x='FinalScore', data=test_df, jitter=0.2, marker='o', 
alpha=0.7, color='b')

bp=sns.pointplot(y=test_df['pbl8'], x=test_df['FinalScore'], color='k', 
markers='x', linestyles='', scale=1.2, errwidth=0.0, capsize=0.15)
bp=sns.boxplot(y='pbl8',  x = 'FinalScore', data=test_df, width=0.5, 
palette="Spectral", linewidth=2, color='b')
bp=sns.stripplot(y='pbl8', x='FinalScore', data=df2, jitter=0.3, 
marker='o', alpha=0.7, color='black')


bp.axes.set_title("Section 11", fontsize=20)
bp.set_ylabel("Group Names", fontsize=20)
bp.set_xlabel("Scores", fontsize=20)

plt.xticks(fontsize=20, rotation=90)
plt.yticks(fontsize=20, rotation=0)

0 个答案:

没有答案