0

I have a 3x3 numpy array with 1s and 0s. For example:

[[0,1,0],
[0,0,1],
[1,0,0]

I am displaying it in black and white using matplotlib:

plt.imshow(X,interpolation='nearest',cmap=plt.cm.gray)

When the array has both 1s and 0s, it produces a correct image.

But when all the values are 0s it displays all black, signifying an all 1 array, which is incorrect:

array = [[0,0,0],[0,0,0],[0,0,0]] # displays black image (correct)
array = [[1,1,1],[1,1,1],[1,1,1]] #displays black image (incorrect)

How do I go about solving this?

geek6
  • 19
  • 6
  • Take a look at the `imshow()` docstring, and read about `vmin` and `vmax`. (This is just a comment, because the question is probably a duplicate.) – Warren Weckesser Aug 26 '17 at 19:36
  • While the question is not *exactly* the same, the answer here also answers your question: https://stackoverflow.com/questions/9119139/python-imshow-grayscale-static-color-values – Warren Weckesser Aug 26 '17 at 19:39
  • I couldn't find similar questions - maybe I wasn't using the correct keywords. But I guess it would be inferred from those answers. It works now. Thanks! – geek6 Aug 26 '17 at 19:44

0 Answers0