Boa tarde. Estou plotando um gráfico de barras porém não consigo ajustar o espaçamento entre as 3 barras diferentes do mesmo.
# plota os resultados
diameters = ['<=102', '103-152', '153-203', '203-254', '255-305', '306-356', '357-406', '407-457',
'458-508', '509-610', '611-711', '>711']
width = 0.3
x = np.arange(len(diameters))
fig, ax = plt.subplots(figsize=(12,12))
rects1 = ax.bar(x - width/1.5, count_kmeans, width=width, label='K-means', align='center')
rects2 = ax.bar(x, count_kmedoids, width=width, label='K-medoids', align='center')
rects3 = ax.bar(x + width/1.5, count_hierarquico, width=width, label='Hierarquico', align='center')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Quantidade')
ax.set_title('Comparativo de diâmetros entre algoritmos')
ax.set_xticks(x)
ax.set_xticklabels(diameters)
ax.set_xlabel('Diâmetro nominal (mm)')
ax.legend()
def autolabel(rects):
"""Attach a text label above each bar in *rects*, displaying its height."""
for rect in rects:
height = rect.get_height()
ax.annotate('{}'.format(height),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
autolabel(rects3)
fig.tight_layout()
plt.show()
Segue o grafico