There is a (somewhat) question in StackOverflow:
The problem here was that the shape array (nx, ny, 1) is still considered a three-dimensional array and must be squeeze d or cut into a 2D array.
More generally, the reason for the exception
TypeError: invalid sizes for image data
here: matplotlib.pyplot.imshow() needs a 2D array or a 3D array, and the third size is in the form of 3 or 4!
You can easily check this (these checks are done using imshow , this function is only intended to provide a more specific message if it is not a valid input):
from __future__ import print_function import numpy as np def valid_imshow_data(data): data = np.asarray(data) if data.ndim == 2: return True elif data.ndim == 3: if 3 <= data.shape[2] <= 4: return True else: print('The "data" has 3 dimensions but the last dimension ' 'must have a length of 3 (RGB) or 4 (RGBA), not "{}".' ''.format(data.shape[2])) return False else: print('To visualize an image the data must be 2 dimensional or ' '3 dimensional, not "{}".' ''.format(data.ndim)) return False
In your case:
>>> new_SN_map = np.array([1,2,3]) >>> valid_imshow_data(new_SN_map) To visualize an image the data must be 2 dimensional or 3 dimensional, not "1". False
np.asarray is what is done internally with matplotlib.pyplot.imshow so it is usually best to do this. If you have a numpy array, it is deprecated, but if not (like list ), this is necessary.
In your specific case, you got a 1D array, so you need to add a dimension using np.expand_dims()
import matplotlib.pyplot as plt a = np.array([1,2,3,4,5]) a = np.expand_dims(a, axis=0)

or just use something that accepts 1D arrays like plot :
a = np.array([1,2,3,4,5]) plt.plot(a) plt.show()
