问题描述
我只想从 skimage.exposure 绘制 Matplotlib 直方图,但我得到一个 ValueError: bins must increase monotonically.
原始图像来自 这里 和这里我的代码:
from skimage import io,曝光导入matplotlib.pyplot作为pltimg = io.imread('img/coins_black_small.jpg', as_grey=True)hist,bins=exposure.histogram(img)plt.hist(bins,hist)
ValueError: bins 必须单调增加.
但是当我对bin值进行排序时,会出现相同的错误:
将 numpy 导入为 npsorted_bins = np.sort(bins)plt.hist(sorted_bins,hist)
ValueError: bins 必须单调增加.
我终于尝试检查bins值,但在我看来它们似乎是有序的(有关这种测试的任何建议也将不胜感激):
if any(bins[:-1] >= bins[1:]):打印边框"
没有输出.
对发生的事情有什么建议吗?
我正在尝试学习 Python,所以请放纵一下.这是我的安装(在 Linux Mint 上):
- Python 2.7.13 :: Anaconda 4.3.1(64 位)
- Jupyter 4.2.1
Matplotlib hist
接受数据作为第一个参数,尚未分箱计数.使用 matplotlib bar
绘制它.请注意,与 numpy histogram
不同,skimage exposure.histogram
返回 bin 的中心.
width = bins [1]-bins [0]plt.bar(bins,hist,align ='center',width = width)plt.show()
I just want to draw Matplotlib histograms from skimage.exposure but I get a ValueError: bins must increase monotonically.
The original image comes from here and here my code:
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)
But the same error arises when I sort the bins values:
import numpy as np
sorted_bins = np.sort(bins)
plt.hist(sorted_bins,hist)
I finally tried to check the bins values, but they seem sorted in my opinion (any advice for this kind of test would appreciated also):
if any(bins[:-1] >= bins[1:]):
print "bim"
No output from this.
Any suggestion on what happens?
I'm trying to learn Python, so be indulgent please. Here my install (on Linux Mint):
- Python 2.7.13 :: Anaconda 4.3.1 (64-bit)
- Jupyter 4.2.1
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()
这篇关于垃圾箱必须单调增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!