python错误名称未定义

时间:2017-01-12 10:56:08

标签: python

我正在关注https://www.analyticsvidhya.com/blog/2014/12/image-processing-python-basics/来练习图像处理。

我正在以增量方式编写代码并检查一切是否顺利。到目前为止,我已经编写了以下代码

from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray
import glob
from skimage.io import imread

example_file=glob.glob(r"/home/snowbell/sample.jpg")[0]
im=imread(example_file, as_grey=True)
plt.imshow(im, cmap=cm.gray)
plt.show()

图像位置和图像名称只是我更改的内容。我收到以下错误: -

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    plt.imshow(im, cmap=cm.gray)
NameError: name 'cm' is not defined

1 个答案:

答案 0 :(得分:1)

from matplotlib import cm应该有效。或import matplotlib.cm as cm