[Python] Turn off axes in subplots

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following code:

    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import matplotlib.cm as cm

    img = mpimg.imread("lena.jpg")

    fig, axs = plt.subplots(2, 2)
    axs[0,0].imshow(img, cmap = cm.Greys_r)
    axs[0,0].set_title("Rank = 512")

    rank = 128
    new_img = prune_matrix(rank, img)
    axs[0,1].imshow(new_img, cmap = cm.Greys_r)
    axs[0,1].set_title("Rank = %s" %rank)

    rank = 32
    new_img = prune_matrix(rank, img)
    axs[1,0].imshow(new_img, cmap = cm.Greys_r)
    axs[1,0].set_title("Rank = %s" %rank)

    rank = 16
    new_img = prune_matrix(rank, img)
    axs[1,1].imshow(new_img, cmap = cm.Greys_r)
    axs[1,1].set_title("Rank = %s" %rank)

    plt.show()


    However, the result is pretty ugly because of the values on the axes:

    [​IMG]

    How can I turn off axes values for all subplots simultaneously?

    How to remove axis, legends, and white padding doesn't work because I don't know how to make it work with subplots.

    Continue reading...

Compartilhe esta Página