user308827
user308827

Reputation: 21961

Pandas reduce bar width and move label

I use the following to reduce width of bars in Panda:

for container in ax.containers:
    plt.setp(container, width=.25)

However, on doing this, the labels on the x-axis remain at original position, as seen below. How can I move them to correspond to new bar width. In other words, is there a function to get the x coordinate of the center of each bar?

enter image description here

Upvotes: 0

Views: 717

Answers (1)

Anzel
Anzel

Reputation: 20543

You may want to set the width during plot(), something like this:

df.plot(kind='bar', stacked=True, width=0.25, align='center')

In the document it doesn't show you can set the width, but in fact it will take it as **kwds It will plot with the desired width with aligned x-axis labels.

Upvotes: 1

Related Questions