我想要一个带有我在X轴上声明的所有值的条形图(尽管它们具有相同的名称)。但是,我从Seaborn获得的输出将它们全部分组。你能帮我吗?
这是我的代码,它产生三个小节的输出:
import matplotlib.style as style
style.use('seaborn-poster')
style.use('ggplot')
processing_times = [15.2875, 15.2539, 1.2172, 1.2116, 21.6022, 23.4139, 1.2097, 1.2067, 30.2567, 27.6683, 2.5, 2.55, 28.5]
selection_type = ['NS', 'NS', 'KFold', 'KFold', 'NS', 'NS', 'KFold', 'KFold', 'NS', 'NS',
'Stats', 'Stats', 'NS']
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame({'Processing time in hr': processing_times, 'Feature Selection': selection_type})
ax = sns.barplot(y = 'Processing time in hr', x = 'Feature Selection', data = df )
答案 0 :(得分:2)
您接近了!使用索引将每个值作为自己的条形。
ax = sns.barplot(x=df.index, y="Processing time in hr", hue="Feature Selection", data=df)
ax.set(xticklabels=[]) # Else we'll see arbitrary numbers along the x ax