'K-means Silhouette plt.bar showing white not coloured for some clusters
So I tried to create a bar plot for my silhouette data:
def silMe(way, sil, silhouette_df):
silhouette_df = silhouette_df.sort_values([way, sil])
silhouette_df.index = list(range(len(silhouette_df)))
for cluster in set(silhouette_df[way]):
plt.bar(silhouette_df[silhouette_df[way]==cluster].index,
silhouette_df[silhouette_df[way]==cluster][sil],
color=colourMap_dict[cluster], label='Cluster ' + str(cluster))
plt.title('Silhouette plot')
plt.legend()
plt.xlabel('Number of data point')
plt.ylabel('Silhouette coefficient')
plt.ylim((0, 1.2))
But for some reason some of the bars show white, no matter what colour I choose for that cluster in the colourMap_dict:
colourMap_dict = {0:'cyan',
1:'blue',
2:'orange',
3: 'green',
4: 'yellow',
5: 'red',
6: 'grey',
7: 'black',
8: 'darkred',
9: 'darkblue',
10: 'lightblue',
11: 'darkGreen'}
But if I change the colours, the same bars remain whited out:
I haven't a clue what's going on or how to troubleshoot. I tried with less clusters and it still whited out some of the clusters.
And the plot thickens... This is what it looks like with just cluster 1:
and this is what it looks like with the rest of the clusters:
But when you put them together, part of it is whited out:
I've lost the plot.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|





