Python中matplotlib.pyplot.imshow画灰度图的多种方法

matplotlib库的教程和使用方法此处就不累赘了,网上有十分多优秀的教程资源。此处直接上代码:

def demo():
    # 读取图片
    training_x, training_y, test_x, test_y = dataset.load_mnist_data(1000, 100)
    im = training_x[0]
    # 绘画灰度图的四种方法
    plt.subplot(221); plt.imshow(im, cmap=plt.cm.gray)
    plt.subplot(222); plt.imshow(im, cmap=plt.cm.gray_r)
    plt.subplot(223); plt.imshow(im, cmap='gray')
    plt.subplot(224); plt.imshow(im, cmap='gray_r')
    plt.show()

效果图下图所示:

《Python中matplotlib.pyplot.imshow画灰度图的多种方法》 4种灰度图效果.png

由上图可以看出,
gray_r中的
r表示
reverse,代表
逆转的意思

    原文作者:monitor1379
    原文地址: https://www.jianshu.com/p/8f96318a153f
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞