我只想从skiplage.exposure中绘制Matplotlib柱状图,但是我得到了一个ValueError: bins must increase monotonically.
原始图像来自here,这里是我的代码:
from skimage import io, exposure
import matplotlib.pyplot as plt
img = io.imread('img/coins_black_small.jpg', as_grey=True)
hist,bins=exposure.histogram(img)
plt.hist(bins,hist)
ValueError: bins must increase monotonically.
但是,当我对bins值进行排序时,也会出现同样的错误:
import numpy as np
sorted_bins = np.sort(bins)
plt.hist(sorted_bins,hist)
ValueError: bins must increase monotonically.
我终于试着检查了bins的值,但在我看来它们似乎是排序的(对于这种测试的任何建议也会很感激):
if any(bins[:-1] >= bins[1:]):
print "bim"
没有输出。
有什么建议吗?
我想学Python,所以请宽容一点。这里是我的安装(在Linux Mint上):
Matplotlib
hist
接受数据作为第一个参数,而不是已装箱的计数。使用matplotlibbar
来绘制它。注意,与numpyhistogram
不同,skipageexposure.histogram
返回容器的中心。plt.hist
的签名是plt.hist(data, bins, ...)
。因此,您正试图将已计算的直方图作为bin插入matplotlibhist
函数。直方图当然没有排序,因此“存储箱必须单调增加”-错误被抛出。当然,你可以使用
plt.hist(hist, bins)
,但是直方图的组织编程是否有用是个问题。我猜你只是想简单地描绘出第一次历史编程的结果。为此,使用条形图是有意义的:
相关问题 更多 >
编程相关推荐