matplotlib subplot without gaps but the last one

后端 未结 2 1627
独厮守ぢ
独厮守ぢ 2021-01-27 07:51

I\'m try to figure out how can I achieve the result as reported in the title\'s topic, basically I wish obtain a subplot 1 column 4 row without gaps in the row 1,2,3 and a norma

相关标签:
2条回答
  • 2021-01-27 08:06

    An alternative to the answer by @GlobalTraveler is to chain two Gridspec definitions. See here for more information about the possibilities offered by GridSpec.

    outer_gs = matplotlib.gridspec.GridSpec(2,1, height_ratios=[3,1], hspace=0.2)
    inner_gs = matplotlib.gridspec.GridSpecFromSubplotSpec(3,1, subplot_spec=gs0[0], hspace=0)
    
    fig = plt.figure()
    ax1 = fig.add_subplot(inner_gs[0])
    ax2 = fig.add_subplot(inner_gs[1])
    ax3 = fig.add_subplot(inner_gs[2])
    ax4 = fig.add_subplot(outer_gs[1])
    

    0 讨论(0)
  • 2021-01-27 08:10

    One you could solve this is by inserting another subplot and them playing around with the height ratios. Let's start with the results;

    Which is achieved by:

    import matplotlib.pyplot as plt
    
    
    gs = dict(\
             height_ratios = [1, 1, 1, .2, 1]
             )
    
    fig, ax = plt.subplots(5, 1, gridspec_kw = gs)
    fig.subplots_adjust(hspace = 0)
    ax[3].axis('off')
    fig.show()
    

    You need to play around with the ratios to achieve the desired results, but the approach could be used to achieve what you want.

    0 讨论(0)
提交回复
热议问题