I have a numpy array results
that looks like
[ 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.]
I would like to plot a histogram of it. I have tried
import matplotlib.pyplot as plt
plt.hist(results, bins=range(5))
plt.show()
This gives me a histogram with the x-axis labelled 0.0 0.5 1.0 1.5 2.0 2.5 3.0. 3.5 4.0
.
I would like the x-axis to be labelled 0 1 2 3 instead with the labels in the center of each bar. How can you do that?
(array([ 4., 5., 1., 2.]), array([0, 1, 2, 3, 4])
(with different input values). So I have got different bins, or do I miss something?results
, the second the numbers of 1s (there are eleven of them), the third the number of 2s (there are eight of them) and the last one is the number of 3s (there are three of them). I would like the number0
as a label under the middle of the first bar, the number1
as a label under the middle of the second and so on. Is that clearer?