I would like to get the 2d numpy array from the 2dhist function. After obtaining the counts, I would like to plot the data in the pyplot.imshow() function to further add some information. The integers that are allowed to appear in my list are between 0 and 11 (therefore 12 bins).
However, I get a strange matrix.
data1 = [2, 3, 3, 10, 3, 2, 10, 2, 2, 2, 2, 2, 10, 2, 10, 10, 9, 2, 9, 10,
9, 9, 9, 3, 10, 3, 2, 10, 1]
data2 = [5, 6, 7, 7, 7, 7, 6, 4, 6, 4, 4, 8, 5, 5, 5, 6, 8, 6, 5, 4, 5, 6,
4, 4, 6, 4, 5, 4, 5]
n_bins = 12
fig, ax = plt.subplots()
counts, xedge, yedge, image = ax.hist2d(data1, data2, bins=n_bins)
result:
array([[0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],
[3., 0., 0., 3., 0., 0., 2., 0., 0., 1., 0., 1.],
[2., 0., 0., 0., 0., 0., 1., 0., 0., 2., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[1., 0., 0., 2., 0., 0., 1., 0., 0., 0., 0., 1.],
[2., 0., 0., 2., 0., 0., 3., 0., 0., 1., 0., 0.]])
transposed:
array([[0., 3., 2., 0., 0., 0., 0., 0., 0., 0., 1., 2.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[1., 3., 0., 0., 0., 0., 0., 0., 0., 0., 2., 2.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 2., 1., 0., 0., 0., 0., 0., 0., 0., 1., 3.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 1., 2., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.]])
If we look at the data lists closely, we see that for example the integer 0 never appears. How can therefore be an entry in the first column?
I would very much appreciate your insides. Thank you.