简体   繁体   English

如何在不更改图表条形宽度的情况下近似图表的条形? (Matplotlib)

[英]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. 您可以稍微玩一些数字,以准确地获得所需的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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