zoukankan      html  css  js  c++  java
  • matplotlib subplot 多图合一

    1:第一种方法

    # method1: subplot2grid
        #################
        '''
        第一个参数(3, 3) 是把图分成3行3列
        第二个参数是位置 (0, 0)表示从0行0列开始
        第三个参数  colspan=3  表示列占3列 ,
        第四个参数 rowspan=1  表示行占一行
    
        '''
        plt.figure()
        ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3, rowspan=1)
        ax1.plot([1, 2], [1, 2])
        ax1.set_title('al1_title')
        ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2,)
        ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
        ax4 = plt.subplot2grid((3, 3), (2, 0))
        ax5 = plt.subplot2grid((3, 3), (2, 1))
    
        plt.savefig('./image_dir/grid1.png')
        plt.show()

    2: 第二种方法:

        import matplotlib.pyplot as plt
        import matplotlib.gridspec as gridspec
    
        plt.figure()
        gs = gridspec.GridSpec(3, 3)
        ax1 = plt.subplot(gs[0, :])
        ax2 = plt.subplot(gs[1, :2])
        ax3 = plt.subplot(gs[1:, 2])
        ax4 = plt.subplot(gs[-1, 0])
        ax5 = plt.subplot(gs[-1, -2])
    
        plt.savefig('./image_dir/grid2.png')
        plt.show()

    3: 第三种方法

        # method4
        plt.figure()
        plt.subplot(2, 2, 1)
        plt.plot([0, 1], [0, 1])
        plt.subplot(222)
        plt.plot([0, 1], [0, 2])
        plt.subplot(223)
        plt.plot([0, 1], [0, 3])
        plt.subplot(224)
        plt.plot([0, 1], [0, 4])
        plt.savefig('./image_dir/grid4.png')
        plt.tight_layout()
        plt.show()

    4: 第四种

     # method 3 : easy to define structure
        f, ((ax11, ax12), (ax21, ax22)) = plt.subplots(2, 2, sharex=True, sharey=True)
        ax11.scatter([1, 2], [1, 2])
        plt.savefig('./image_dir/grid3.png')
        plt.tight_layout()
        plt.show()

  • 相关阅读:
    VS2008 SP1 安装时异常处理
    Android和iOS自带的人脸检测API
    FAAST 0.08 动作列表
    C#日期格式化(转)
    希望看这篇文章的人,耐心的看完这个短片
    C#实现转换十六进制
    App Store生存法则:iOS开发者经验分享
    开始的关键不是什么时候开始 而是开始后的坚持
    Eclipse IDE
    最近需要看的网站
  • 原文地址:https://www.cnblogs.com/heguihui/p/12183302.html
Copyright © 2011-2022 走看看