How can I center my bin labels in x and y for a matplotlib pyplot 2d histogram?
I've tried the following:
import numpy as np
import matplotlib.pyplot as plt
ns = np.random.uniform(low=0,high=6,size=200)
dets = np.random.uniform(low=0,high=15,size=200)
plt.figure()
h = plt.hist2d(dets,ns,bins=(16,7))
plt.colorbar(h[3])
plt.xticks(np.arange(0,16,1))
plt.yticks(np.arange(0,7,1))
plt.show()
and as you can see, the bin labels are not centered. How can I edit the labeling scheme so that the bin labels ([0,15]
and [0,6]
) are at the center of the bins?