Matplotlib: Repositioning a subplot in a grid of subplots

前端 未结 2 1979
鱼传尺愫
鱼传尺愫 2021-02-08 20:40

I am trying to make a plot with 7 subplots. At the moment I am plotting two columns, one with four plots and the other with three, i.e. like this:

2条回答
  •  失恋的感觉
    2021-02-08 20:56

    Use grid spec (doc) with a 4x4 grid, and have each plot span 2 columns as such:

    import matplotlib.gridspec as gridspec
    gs = gridspec.GridSpec(4, 4)
    ax1 = plt.subplot(gs[0, 0:2])
    ax2 = plt.subplot(gs[0,2:])
    ax3 = plt.subplot(gs[1,0:2])
    ax4 = plt.subplot(gs[1,2:])
    ax5 = plt.subplot(gs[2,0:2])
    ax6 = plt.subplot(gs[2,2:])
    ax7 = plt.subplot(gs[3,1:3])
    fig = gcf()
    gs.tight_layout(fig)
    ax_lst = [ax1,ax2,ax3,ax4,ax5,ax6,ax7]
    

提交回复
热议问题