简体   繁体   中英

How can I approximate the bars of a chart without changing the width of those bars? (Matplotlib)

So, basically what I want is to reduce the distance between two bars, but all the solutions that I read on the internet were people changing the width of the bars, and that is not what I want.

This is my chart:

x = ['Goal (95%)','Achieved (100%)']
y = [95,100]

plt.bar(x,y,color = ('darkcyan','green'), width = 0.2)
plt.ylabel('Percentage (%)')

Imgur

I expect something like this:

Imgur

If I change the width I can reduce the distance, but the bars get very thick and I want them thin.

plt.bar(x,y,color = ('darkcyan','green'), width = 0.8)
plt.ylabel('Percentage (%)')

Imgur

I got something closely approximating what you want working by changing the figure size and then updating the width.

plt.figure(figsize=(3,4))
plt.bar(x,y,color = ('darkcyan','green'), width = 0.8)

Usually when you scale the figure size down the bars just get more narrow, so combining that with thicker bars seemed to do the trick. You can play with the numbers a little to get it exactly how you want it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM