code: def print_figure(fig, fmt="png", bbox_inches="tight", **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``.
      """
      from matplotlib import rcParams
  
      # 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 = dict(
          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()
      fig.canvas.print_figure(bytes_io, **kw)
      data = bytes_io.getvalue()
      if fmt == "svg":
          data = data.decode("utf-8")
      return data
  
file_path: catboost/contrib/python/ipython/py2/IPython/core/pylabtools.py
imports: from __future__ import print_function
  from io import BytesIO
  from IPython.core.display import _pngxy
  from IPython.utils.decorators import flag_calls
  from IPython.utils import py3compat
label_desc: Use image node_id 3 for calling a global function with example usage: print_figure(fig, fmt, bbox_inches) and returns: data