matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)
在使用matplotlib繪製條形圖時,由於width默認爲0.8,條形圖中會產生很多間隙,使用bar函數時,添加width = 1即可消除間隔
消除間隔前
消除間隔後
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()