Hi Paula,

Glad you liked it. About your question, the matplotlib can plot either rowsXcolumsXchannels (3D array with 3 or 4 channels — in chase of alpha) or just rowsXcolumns. If you take a look at the documentation (https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.imshow.html) you can see:

Parameters:X : array-like or PIL image

The image data. Supported array shapes are:

  • (M, N): an image with scalar data. The data is visualized using a colormap.
  • (M, N, 3): an image with RGB values (0–1 float or 0–255 int).
  • (M, N, 4): an image with RGBA values (0–1 float or 0–255 int), i.e. including transparency.

The first two dimensions (M, N) define the rows and columns of the image.

Out-of-range RGB(A) values are clipped.

I don’t remember exactly the output of this code, but if it is (M, N, 1) and matplotlib is refusing it, you can just use squeeze function to get rid of this extra dimension.

Hope it helps. Feel free to ask you have further doubts.

Doctorate student @ Université Paul Sabatier (Toulouse). Water Resources Specialist at the Brazilian National Water Agency.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store