code: def get_ax_size(ax, fig):
      
      bbox = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
      width, height = bbox.width, bbox.height
      width *= fig.dpi
      height *= fig.dpi
docs: Get axis size
  
      Parameters
      ----------
      ax : matplotlib.axis
          Axis object from matplotlib.
      fig : matplotlib.Figure
          Figure.