0

How do I plot an image in gray scale? I would imagine the following example would do this, but I get a color image. Do I need to apply the colormap in some other way?

import numpy as np
import matplotlib.pyplot as plt

img2 = np.array([[[248, 255, 255],
        [ 79, 109,  97],
        [  0,  15,   0],
        [223, 255, 248],
        [ 85,  87,  84]],

       [[255, 255, 246],
        [126, 106,  99],
        [ 25,   0,   0],
        [220, 175, 172],
        [ 30,  17,   9]],

       [[ 39,   0,   0],
        [255, 175, 179],
        [ 86,   0,   0],
        [106,   0,   0],
        [ 66,   0,   0]],

       [[181,  35,  46],
        [181,  32,  36],
        [166,  42,  34],
        [146,  43,  24],
        [195,  20,  35]],

       [[243,   0,  29],
        [200,  22,  22],
        [255, 202, 159],
        [243, 255, 186],
        [254,   0,  26]]], dtype='uint8')

plt.imshow(img2,cmap='gray')

plt.show()

I am working in python 2.7 in a jupyter notebook.

Chogg
  • 389
  • 2
  • 19
  • This might not be the best place to ask this question. Apologies. If I should post this to a different forum, please could you suggest where. Thanks in advance. – Chogg Nov 21 '19 at 15:47
  • 1
    You have a code that does not do what you want, so this is perfectly fine to be asked here. However, it's been asked and answered before already, e.g. in [this question](https://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python). So always check existing Q&A first. – ImportanceOfBeingErnest Nov 21 '19 at 15:53

0 Answers0