如何避免在matplotlib.pyplot imshow()中进行自动伪着色 [英] How to avoid automatic pseudo coloring in matplotlib.pyplot imshow()
问题描述
我有一个要打印为图像的28x28 numpy ndarray.由于它是灰度图片,因此每个像素只有一个颜色值.这些值从-0.5缩放到0.5. 我使用plt.imshow(array).当我这样做时,图像将使用喷射色图而不是灰度打印出来.
I have a 28x28 numpy ndarray that I want to print out as an image. Since it is a grayscale picture, it only has one color value per pixel. These values are scaled from -0.5 to 0.5. I use plt.imshow(array). When I do that, the image gets printed out with the jet colormap, instead of grayscale.
如果我应用cmap ='gray',我会得到灰度图像,但是为什么默认的imshow()使用喷射色图呢?
If I apply cmap = 'gray' I get my grayscale image, but why is the default imshow() using the jet colormap)?
推荐答案
要防止matplotlib默认使用"jet"颜色映射,您需要修改与matplotlibrc文件中默认cmap对应的行,通常在〜/中找到.config/matplotlib/matplotlibrc:
To prevent matplotlib from using the "jet" colormap as default you need to modify the line corresponding to the default cmap in the matplotlibrc file, usually found in ~/.config/matplotlib/matplotlibrc:
image.cmap : gray # gray | jet etc...
此外,我鼓励大家在 matplotlib 2.0
这篇关于如何避免在matplotlib.pyplot imshow()中进行自动伪着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!