With matplotlib’s hist
function, how can one make it display the count for each bin over the bar?
For example,
JavaScript
x
4
1
import matplotlib.pyplot as plt
2
data = [ ] # some data
3
plt.hist(data, bins=10)
4
How can we make the count in each bin display over its bar?
Advertisement
Answer
it seems hist
can’t do this,you can write some like :
JavaScript
1
6
1
your_bins=20
2
data=[]
3
arr=plt.hist(data,bins=your_bins)
4
for i in range(your_bins):
5
plt.text(arr[1][i],arr[0][i],str(arr[0][i]))
6