1

I'm plotting a horizontal barplot using matplotlib.pyplot.barh, and want to move the bar positions. I didn't find any argument that supports this. Anyone had the same problem?

ax1.set_title('Number of Accounts', size=12)
ax1.invert_yaxis()
ax1.invert_xaxis()
ax1.barh(c['Customer Group'], c['n_accts'],color='#f4be92')

Right now the bar for 1 is in between 0 and 1, and the one for 2 is in between 1 and 2. Is there a way to move the bars to where their corresponding numbers are?

enter image description here

1
  • I suppose it depends on what c['Customer Group'] is and how you produced the labels. Both is not shown in the question. See minimal reproducible example. Commented Jan 10, 2019 at 20:31

1 Answer 1

1

You should use a centered alignment. To do so, you can use pass align='center' as an argument to your ax.barh. So just use

ax1.barh(c['Customer Group'], c['n_accts'],color='#f4be92', align='center')

It will center the bars on the y axis. See the docs here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! so the default value for the align argument is 'center', so passing 'center' didn't make a difference, but passing align='edge' worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.