[Python] delete the redundant axis in colorbar

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    This part of code is from my teacher's code:

    fig, ax = plt.subplots(
    1,
    4,
    figsize=[18, 4],
    sharex=True,
    sharey=True,
    )

    for i in range(4):
    ax.imshow(np.random.rand(200, 800), cmap="viridis_r", origin="lower")

    divider = make_axes_locatable(ax[-1])
    cax = divider.new_horizontal(size="4%", pad="2%")
    fig.add_axes(cax)
    fig.colorbar(mpl.cm.ScalarMappable(cmap=mpl.cm.viridis_r, norm=norm), cax=cax)

    plt.show()


    [​IMG]

    OK this colorbar is normal, but in another part of code:

    [​IMG]

    why here the colorbar has another x axis with very dense ticks? I don't want them!

    cax.set_xticks([]) does not work

    Continue reading...

Compartilhe esta Página