I'm using the hist2d function of matplotlib.pyplot, giving it input some coordinates (x,y).
I would like, after having defined the histogram, to get the center of each bin, i.e., the coordinates of the center of each bin.
Is there an easy way to get them?
The return values of
plt.histandplt.hist2dinclude bin edges, so take the mean of the left edges and right edges:plt.histplt.hist2dNote that you can use numpy functions if preferred, though I find it less readable in this case:
Full example with
plt.hist2d:Output: