matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)
在使用matplotlib绘制条形图时,由于width默认为0.8,条形图中会产生很多间隙,使用bar函数时,添加width = 1即可消除间隔
消除间隔前
![](https://i-blog.csdnimg.cn/blog_migrate/24bba8dda451b752e8e76ce1c4fb6fb8.png)
消除间隔后
![](https://i-blog.csdnimg.cn/blog_migrate/132dd911b4c0b1667ec1ee37dcb67d72.png)
import matplotlib.pyplot as plt
import random
dic={}
for i in range(1000):
dic[int(i)]=random.randint(30,100)
plt.bar(dic.keys(), dic.values(), width=1, alpha=0.5, color='b')
plt.show()