Other answers just don't do this for me. The advantage of using plt.bar over plt.hist is that the bar can use align='center' :
import numpy as np import matplotlib.pyplot as plt arr = np.array([ 0., 2., 0., 0., 0., 0., 3., 0., 0., 0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 2., 0., 3., 1., 0., 0., 2., 2., 0., 0., 0., 0., 0., 0., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 3., 1., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 2., 2.]) labels, counts = np.unique(arr, return_counts=True) plt.bar(labels, counts, align='center') plt.gca().set_xticks(labels) plt.show()
