def plot_hist(clusters_list, logname,colors_list):
"""
DESCRIPTION
This function is used to plot a histogram with the cluster size.
Args:
cluster_number_list (list) : list of cluster label in order or appearance
output (str) : output logname
Returns:
None
"""
if mpl.__version__[0] == "2":
STYLE = "classic"
if STYLE in plt.style.available:
plt.style.use(STYLE)
values = []
labels = []
for cl in clusters_list:
#occurence.append((cl.id, cl.size))
values.append(cl.size)
labels.append(cl.id)
#Sorting occurence dict by cluster size
#### Configuration plot
width = 0.7 # bars size
index = np.arange(len(values)) # the x locations for the groups
fig, ax = plt.subplots()
bp = ax.bar(index, values, width, color=colors_list, label="Cluster size")
#add value on top of bars, adapted from matplotlib doc
for rect in bp:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.0*height,
'%d' % int(height),
ha='center', va='bottom')
plt.xlabel("Clusters")
plt.ylabel("Number of members")
plt.title("Distribution within clusters")
plt.xticks(index+(width/2), labels)
plt.tight_layout()
plt.savefig("{0}/{0}-hist.png".format(logname), dpi=DPI,transparent=True)
plt.close()
评论列表
文章目录