图像数据无法转换为float - python

时间:2017-05-06 20:15:40

标签: python image plot axes

我试图在python中显示图像,我不是100%确定为什么imshow()会抛出错误。

错误跟踪是: 回溯(最近一次调用最后一次):

  File "knn.py", line 65, in <module>
    digit_axes.imshow(paths[0],cmap = cm.Greys_r)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1892, in inner
    return func(ax, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 5118, in imshow
    im.set_data(X)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/image.py", line 545, in set_data
    raise TypeError("Image data can not convert to float")
TypeError: Image data can not convert to float

代码如下:

paths = []
paths.append('./images/image1.png')

digit_axes = main_figure.add_subplot(211)

digit_axes.get_xaxis().set_visible(False)
digit_axes.get_yaxis().set_visible(False)
digit_axes.set_title('Image')

digit_axes.imshow(paths[0],cmap = cm.Greys_r)

1 个答案:

答案 0 :(得分:0)

我认为我通过使用imread()

找到了解决方案
img = imread(paths[0])
digit_axes.imshow(img,cmap = cm.Greys_r)