matplotlib stacked barplot remove gaps in columns

22 Views Asked by At

I want to create a matplotlib stacked barplot with ordered values. However, this is the result I got: Gap in stacked barplot column

I want to remove those gaps from the column, bit idk how to do it. Here is the code that I've used:

val1 = [ 2.20810623,  9.1243303,   9.78813997, 11.19015164, 13.71907402, 16.07695801,
 20.60492477, 23.69439942, 25.23510585, 29.3574946 ]
val2 = [70.6425054,  74.76489415, 76.30560058, 79.39507523, 83.92304199, 86.28092598,
 88.80984836, 90.21186003, 90.8756697,  97.79189377]

ax.bar(x=df[df['team'] == 'A']['source'], height=val1, label = "A")
ax.bar(x=df[df['team'] == 'A']['source'], height=val2, label = "B",bottom=val1)
for bar in ax.patches:
  ax.text(bar.get_x() + bar.get_width() / 2,
          bar.get_height() / 2 + bar.get_y(),
          round(bar.get_height()), ha = 'center',
          color = 'w', weight = 'bold', size = 10)
ax.legend()
plt.xticks(rotation=90)
ax.set_ylabel('percentage')

0

There are 0 best solutions below