code: def print_figure(
      fig, fmt="png", bbox_inches="tight", base64=False, **kwargs
  ):
      """Print a figure to an image, and return the resulting file data
  
      Returned data will be bytes unless ``fmt='svg'``,
      in which case it will be unicode.
  
      Any keyword args are passed to fig.canvas.print_figure,
      such as ``quality`` or ``bbox_inches``.
  
      If `base64` is True, return base64-encoded str instead of raw bytes
      for binary-encoded image formats
  
      .. versionadded:: 7.29
          base64 argument
      """
      # When there's an empty figure, we shouldn't return anything, otherwise we
      # get big blank areas in the qt console.
      if not fig.axes and not fig.lines:
          return
  
      dpi = fig.dpi
      if fmt == "retina":
          dpi = dpi * 2
          fmt = "png"
  
      # build keyword args
      kw = {
          "format": fmt,
          "facecolor": fig.get_facecolor(),
          "edgecolor": fig.get_edgecolor(),
          "dpi": dpi,
          "bbox_inches": bbox_inches,
      }
      # **kwargs get higher priority
      kw.update(kwargs)
  
      bytes_io = BytesIO()
      if fig.canvas is None:
          from matplotlib.backend_bases import FigureCanvasBase
  
          FigureCanvasBase(fig)
  
      fig.canvas.print_figure(bytes_io, **kw)
      data = bytes_io.getvalue()
      if fmt == "svg":
          data = data.decode("utf-8")
      elif base64:
          data = b2a_base64(data, newline=False).decode("ascii")
      return data
  
file_path: catboost/contrib/python/ipython/py3/IPython/core/pylabtools.py
imports: from io import BytesIO
  from binascii import b2a_base64
  from functools import partial
  import warnings
  from IPython.core.display import _pngxy
  from IPython.utils.decorators import flag_calls
label_desc: Use image node_id 3 for calling a global function with example usage: print_figure(fig, fmt, bbox_inches, base64) and returns: data