【问题标题】:How to align two plots in the center of three column plot in matplotlib如何在matplotlib中的三列图的中心对齐两个图
【发布时间】:2021-04-13 13:59:07
【问题描述】:

我正在尝试制作一个总共有 14 个地块的地块。所以,我在每一行中绘制 3 个图。在最后一行,还有两个可以绘制在特定列号的图。但是,为了使图形看起来更同步,如何将最后两个图绘制在列的中心。下面是我想要实现的图片:

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    你可以使用matplotlib.gridspec如下:

    import matplotlib.pyplot as plt
    import matplotlib.gridspec as gridspec
        
    if __name__ == '__main__':
        fig = plt.figure(figsize=(15,20),tight_layout=True)
        
        spec = gridspec.GridSpec(ncols=8, nrows=3, figure=fig)
        ax1 = fig.add_subplot(spec[0,1:3])
        ax2 = fig.add_subplot(spec[0,3:5])
        ax3 = fig.add_subplot(spec[0,5:7])
        ax4 = fig.add_subplot(spec[1,1:3])
        ax5 = fig.add_subplot(spec[1,3:5])
        ax6 = fig.add_subplot(spec[1,5:7])
        ax7 = fig.add_subplot(spec[2,2:4])
        ax8 = fig.add_subplot(spec[2,4:6])
        plt.show() # bbox_inches='tight'
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 2018-05-16
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 2013-10-18
      • 2014-05-14
      相关资源
      最近更新 更多