matplotlib displays the grayscale image as purple

import numpy as np
import matplotlib.pyplot as plt

a = np.zeros((3,5))
plt.imshow(a)

The obtained picture is indeed the following, not black.
Insert picture description here
The answer I found for a long time:
If we don’t specify the color space, matplotlib默认的cmap即颜料板是十色环that is to say, it is not our intuitive gray space or hot space, but a simple color cycle. The relationship is not even a one-to-one relationship. To put it simply 第一个值会被映射成紫色,不管是0还是1;如果只有一个值,那就是全紫;只有后面就新值才会是后一种颜色, I tried it out as yellow; then it was emerald green. It has nothing to do with the value, only the order in which it appears.
If you want to display a grayscale image, you must also specify the imshow parameter, that is

Insert picture description here

Guess you like

Origin blog.csdn.net/AWhiteDongDong/article/details/111186389