code: def get_default_margins(self):
          
          trans = self.fig.transFigure.inverted().transform
  
          # Static margins
          l, t, r, b = self.axesmargins
          (l, b), (r, t) = trans(((l, b), (r, t)))
  
          # Extent
          dl, dt, dr, db = 0, 0, 0, 0
          for i, ax in enumerate(self.fig.get_axes()):
              (x0, y0),(x1, y1) = ax.get_position().get_points()
              try:
                  (ox0, oy0), (ox1, oy1) = ax.get_tightbbox(self.canvas.get_renderer()).get_points()
                  (ox0, oy0), (ox1, oy1) = trans(((ox0 ,oy0),(ox1 ,oy1)))
                  dl = min(0.2, max(dl, (x0 - ox0)))
                  dt = min(0.2, max(dt, (oy1 - y1)))
                  dr = min(0.2, max(dr, (ox1 - x1)))
                  db = min(0.2, max(db, (y0 - oy0)))
              except:
                  pass
  
          return (l + dl, t + dt, r + dr, b + db)
docs: get default margins