3

I am trying to use python with jupyter notebook to come up with a scheme where you can hold on to a smart lightbulb and get information from the hand by diffuse reflectance. I've managed to make all of that work, and all of this is saved in a variable PIX:

PIX = np.array(pictures)
print(PIX.shape)

And this outputs an (81,480,640,3) just as expected (the 81 represents the visible spectrum converted to RGB so that the lamp gets it).

However, I now want to visualize the data, and I thought that imshow was the perfect implementation. I looked around and Datacamp had a nice summary of this in action and copied and pasted from https://campus.datacamp.com/courses/biomedical-image-analysis-in-python/exploration?ex=11. I changed some of the variables so that the script looks like the following:

# Plot the images on a subplots array 
fig, axes = 
plt.subplots(int(PIX.shape[0]/9),int(PIX.shape[0]/9))

for i, ax in enumerate(axes):
    axes[i].imshow(PIX[i,:,:,0], interpolation='none')
# Render the figure
plt.show()

Again, this is fairly simple. However, I get the error:

AttributeError                            Traceback (most recent call last)
<ipython-input-20-a7bb604d1828> in <module>
      3 
      4 for i, ax in enumerate(axes):
----> 5     axes[i].imshow(PIX[i,:,:,0], interpolation='none')
      6 # Render the figure
      7 plt.show()

AttributeError: 'numpy.ndarray' object has no attribute 'imshow' 

I tried the fixes on 'numpy.ndarray' object has no attribute 'imshow' and 'numpy.ndarray' object has no attribute 'show' using matplotlib, who seemed to have similar problems. However, none of the fixes seem to work in my case.

Any help would be appreciated!

1
  • I tried to do that too, but it returns TypeError: 'Figure' object is not subscriptable, so I don't think that fig is enumerable. And just doing fig.imshow returns AttributeError: 'Figure' object has no attribute 'imshow' Commented Aug 14, 2020 at 14:29

1 Answer 1

9

axes is a 2D ndarray so you have to use two indices.

Alternatively, you could replace

for i, ax in enumerate(axes)

With

for i, ax in enumerate(axes.ravel())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.