bins must increase monotonically
Matplotlib hist
accept data as first argument, not already binned counts. Use matplotlib bar
to plot it. Note that unlike numpy histogram
, skimage exposure.histogram
returns the centers of bins.
width = bins[1] - bins[0]
plt.bar(bins, hist, align='center', width=width)
plt.show()
The signature of plt.hist
is plt.hist(data, bins, ...)
. So you are trying to plug the already computed histogram as bins into the matplotlib hist
function. The histogram is of course not sorted and therefore the "bins must increase monotonically"-error is thrown.
While you could of course use plt.hist(hist, bins)
, it's questionable if histogramming a histogram is of any use. I would guess that you want to simply plot the result of the first histogramming.
Using a bar chart would make sense for this purpose:
hist,bins=numpy.histogram(img)
plt.bar(bins[:-1], hist, width=(bins[-1]-bins[-2]), align="edge")
The correct solution is:
All bin values must be whole numbers, no decimals! You can use round() function.