K
K
Kirushkaa2020-10-02 20:14:32
Python
Kirushkaa, 2020-10-02 20:14:32

Why doesn't cmap argument work in mathplotlib?

Hello. Faced such a problem.
There is a task "The code in the next cell loads a photo of a kitten as a Numpy array." 5f775f4e8c843432139876.png
I wrote the code and it seems to work correctly, but the image does not turn gray as in this photo 5f775f896e172603307401.png
. I get something like this
5f775fca0197b832684278.png
Please help)

def slicing(kitten):
    
    img1 = [[[y[0], 0, 0] for y in x] for x in kitten]
    img2 = [[[0, y[0], 0] for y in x] for x in kitten]
    img3 = [[[0, 0, y[0]] for y in x] for x in kitten]
    
    fig, (img1_, img2_, img3_) = plt.subplots(
        nrows=3, ncols=1,
        figsize = (9,12),
        sharex=True)
    
    
    img1_.set_title("R")
    img1_.imshow(img1, cmap = 'gray')
    
    img2_.set_title("G")
    img2_.imshow(img2, cmap = 'gray')
    
    img3_.set_title("B")
    img3_.imshow(img3, cmap = 'gray')
    
    plt.show()
    
        
slicing(kitten)

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
C
Cyril, 2020-10-03
@Kirushkaa

Because slice it wrong, IMHO. It is necessary not to leave only one color component, but to replace two other components with it: [RGB] -> [RRR], [GGG], [BBB], and not [R00], [0G0], [00B].
Well, try something like this: https://stackoverflow.com/questions/25625952/matpl...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question