I am trying to create a histogram for the following data
x = [2, 3, 4, 5]
y = [1, 1, 1, 1]
I am using the following code which is, for example, described in and old version of an answer to this question about how to generate 2D histograms in matplotlib.
import matplotlib.pyplot as plt
import numpy as np
bins = np.arange(-0.5, 5.5, 1.0), np.arange(-0.5, 5.5, 1.0)
heatmap, xedges, yedges = np.histogram2d(x, y, bins=bins)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.clf()
plt.imshow(heatmap,
extent=extent,
interpolation='nearest',
cmap=plt.get_cmap('viridis'), # use nicer color map
)
plt.colorbar()
plt.xlabel('x')
plt.ylabel('y')
However, the plot that this produces seems rotated in some way.
I was expecting this:
But I got
Obviously, this does not match my input data. The coordinates highlighted in this plot are (1, 0), (1, 1), (1, 2), (1, 3)
.
What is going on?