Is it possible to switch X axis in Python matplotlib.pyplot.hist from bin edges to exact values? In other words this is what I get:
dataset = [0,1,1,1,2,2,3,3,4]
plt.hist(dataset, 5, rwidth=0.9)

and this what I need:

You can first compute the frequencies and then use a bar plot
from collections import Counter
import matplotlib.pyplot as plt
dataset = [0,1,1,1,2,2,3,3,4]
freqs = Counter(dataset)
plt.bar(freqs.keys(), freqs.values(), width=0.9)
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With