Currently I have this code to show three images:
imshow(image1, title='1')
imshow(image2, title='2')
imshow(image3, title='3')
And it works fine. But I am trying to put them all three in a row instead of column.
Here is the code I have tried:
f = plt.figure()
f.add_subplot(1,3,1)
plt.imshow(image1)
f.add_subplot(1,3,2)
plt.imshow(image2)
f.add_subplot(1,3,3)
plt.imshow(image3)
It throws
TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
If I do
f = plt.figure()
f.add_subplot(1,3,1)
plt.imshow(image1.cpu())
f.add_subplot(1,3,2)
plt.imshow(image2.cpu())
f.add_subplot(1,3,3)
plt.imshow(image3.cpu())
It throws
TypeError: Invalid shape (1, 3, 128, 128) for image data
How should I fix this or is there an easier way to implement it?
subplotsfunction, specifying the number of rows you want through thencolsargument.fig, axs = plt.subplots(nrows=1, ncols=3) axs[0].imshow(image1.cpu()) axs[1].imshow(image2.cpu()) axs[2].imshow(image3.cpu())and still gettingTypeError: Invalid shape (1, 3, 128, 128) for image datacpu()method is transforming the arrayimagewith (I suppose) dimensions (128,128) into another of dimensions (1,3,128,128), which is invalid for theimshowfunction. The argument of this function must be a two dimensional array (or 3-dimensional if you are working with RGB data), representing the data values of the pixels of the image.