code: def figure2base64(fig):
      io = BytesIO()
      fig.savefig(io, format="png")
      try:
          fig_base64 = base64.encodebytes(io.getvalue())  # py3
      except Exception:
          fig_base64 = base64.encodestring(io.getvalue())  # py2
      return fig_base64
  
file_path: sklearn-evaluation/src/sklearn_evaluation/report/serialize.py
imports: from functools import reduce
  import base64
  from six import BytesIO
  import matplotlib
label_desc: Use image node_id 3 for calling a global function with example usage: figure2base64(fig) and returns: fig_base64