'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'}

plot showing white bars instead of coloured

But if I change the colours, the same bars remain whited out:

bar plot of silhouette showing whited out bars

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:

bar plot with cluster 1 only

and this is what it looks like with the rest of the clusters:

bar plot with rest of clusters

But when you put them together, part of it is whited out:

clusters together, 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