[Python] Plot with 8 subplots where 4x4 with horizontal space

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a plot where I just want some distance between the first and second set of plots. Basically when you plot below, you can see the y-axis values off ax5 and ax7 there that is where I need a space from the first set. When I chance wspace-hspace below it just puts the distance between all of them. Can't really figure out how to do this, any help is appreciated.

    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(14, 12))

    gs = fig.add_gridspec(2, 4, hspace=0, wspace=0)

    ax1 = fig.add_subplot(gs[0, 0])
    ax2 = fig.add_subplot(gs[0, 1])
    ax3 = fig.add_subplot(gs[1, 0])
    ax4 = fig.add_subplot(gs[1, 1])

    ax5 = fig.add_subplot(gs[0, 2])
    ax6 = fig.add_subplot(gs[0, 3])
    ax7 = fig.add_subplot(gs[1, 2])
    ax8 = fig.add_subplot(gs[1, 3])


    for ax in [ax1, ax2, ax3, ax4]:
    ax.plot([0, 1], [0, 1])

    for ax in [ax5, ax6, ax7, ax8]:
    ax.plot([0, 1], [1, 0])

    axes_to_modify = [ax2, ax4, ax6, ax8]

    for ax in axes_to_modify:
    ax.set_xlabel('')
    ax.set_ylabel('')
    ax.set_xticklabels([])
    ax.set_yticklabels([])

    plt.show()

    Continue reading...

Compartilhe esta Página