Python 删除空组或将其堆叠在条形图中

Python 删除空组或将其堆叠在条形图中,python,seaborn,Python,Seaborn,这是我的密码 test = clusters[['Cluster', 'Titularidad_Centro' ,'Freq']].groupby(['Cluster', 'Titularidad_Centro'], as_index = True).sum() test = test.sort_values(['Cluster','Freq'], ascending=[True, False]) test['Porcentaje'] = test.groupby(['Cluster']).ap

这是我的密码

test = clusters[['Cluster', 'Titularidad_Centro' ,'Freq']].groupby(['Cluster', 'Titularidad_Centro'], as_index = True).sum()
test = test.sort_values(['Cluster','Freq'], ascending=[True, False])
test['Porcentaje'] = test.groupby(['Cluster']).apply(lambda x: 100 * x / float(x.sum()))
test = test.groupby(['Cluster']).head(1).reset_index()
sns.factorplot(x='Cluster', y='Porcentaje', data=test, hue='Titularidad_Centro', kind='bar',  palette="husl", aspect=20/8.27)
plt.show()
我得到了这个阴谋


但是我需要一个按簇排列的条,所以我需要删除空类别或堆叠组,因为我只有一个按簇排列的类别。

Set dodge=False。但看起来您使用的是旧版本,可能需要先进行更新。

如果您不需要/不想要seaborn提供的输出,请不要使用seaborn。根据Titularida_Centro,简单地使用matplotlib和颜色绘制一个条形图。我的问题是,我不知道Titularida_Centro中的类别数量,根据我所看到的,matplotlib中的着色是通过手动映射颜色和类别来完成的。我还没有看到如何使用第三个变量。