code: def fix_aspect(fig, nrows, ncols, title=None, extra_artists=[],
                 vspace=0.2, hspace=0.2):
      
      fig.canvas.draw()
      w, h = fig.get_size_inches()
  
      # Compute maximum height and width of each row and columns
      rows = resolve_rows([[ax] for ax in fig.axes])
      rs, cs = len(rows), max([len(r) for r in rows])
      heights = [[] for i in range(cs)]
      widths = [[] for i in range(rs)]
      for r, row in enumerate(rows):
          for c, ax in enumerate(row):
              bbox = ax.get_tightbbox(fig.canvas.get_renderer())
              heights[c].append(bbox.height)
              widths[r].append(bbox.width)
      height = (max([sum(c) for c in heights])) + nrows*vspace*fig.dpi
      width = (max([sum(r) for r in widths])) + ncols*hspace*fig.dpi
  
      # Compute aspect and set new size (in inches)
      aspect = height/width
      offset = 0
      if title and title.get_text():
          offset = title.get_window_extent().height/fig.dpi
      fig.set_size_inches(w, (w*aspect)+offset)
  
      # Redraw and adjust title position if defined
      fig.canvas.draw()
      if title and title.get_text():
          extra_artists = [a for a in extra_artists
                           if a is not title]
          bbox = get_tight_bbox(fig, extra_artists)
          top = bbox.intervaly[1]
          if title and title.get_text():
              title.set_y((top/(w*aspect)))
docs: Calculate heights and widths of axes and adjust
      the size of the figure to match the aspect.