我想得到一张有我在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 )
最佳答案
你很亲密!使用索引获取每个值作为其自己的条。
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
关于python - “X值分组在带有seaborn的条形图中的输出中”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56055842/