code: def save_figures(image_path, fig_count, gallery_conf):
      """Save all open matplotlib figures of the example code-block
  
      Parameters
      ----------
      image_path : str
          Path where plots are saved (format string which accepts figure number)
      fig_count : int
          Previous figure number count. Figure number add from this number
      gallery_conf : dict
          Contains the configuration of Sphinx-Gallery
  
      Returns
      -------
      images_rst : str
          rst code to embed the images in the document
      fig_num : int
          number of figures saved
      """
      figure_list = []
  
      for fig_num in plt.get_fignums():
          # Set the fig_num figure as the current figure as we can't
          # save a figure that's not the current figure.
          fig = plt.figure(fig_num)
          kwargs = {}
          to_rgba = matplotlib.colors.colorConverter.to_rgba
          for attr in ["facecolor", "edgecolor"]:
              fig_attr = getattr(fig, "get_" + attr)()
              default_attr = matplotlib.rcParams["figure." + attr]
              if to_rgba(fig_attr) != to_rgba(default_attr):
                  kwargs[attr] = fig_attr
  
          current_fig = image_path.format(fig_count + fig_num)
          fig.savefig(current_fig, **kwargs)
          figure_list.append(current_fig)
  
      if gallery_conf.get("find_mayavi_figures", False):
          from mayavi import mlab
  
          e = mlab.get_engine()
          last_matplotlib_fig_num = fig_count + len(figure_list)
          total_fig_num = last_matplotlib_fig_num + len(e.scenes)
          mayavi_fig_nums = range(
              last_matplotlib_fig_num + 1, total_fig_num + 1
          )
  
          for scene, mayavi_fig_num in zip(e.scenes, mayavi_fig_nums):
              current_fig = image_path.format(mayavi_fig_num)
              mlab.savefig(current_fig, figure=scene)
              # make sure the image is not too large
              scale_image(current_fig, current_fig, 850, 999)
              figure_list.append(current_fig)
          mlab.close(all=True)
  
      return figure_rst(figure_list, gallery_conf["src_dir"])
  
imports: from __future__ import division, print_function, absolute_import
  from time import time
  import ast
  import codecs
  import hashlib
  import os
  import re
  import shutil
  import subprocess
  import sys
  import traceback
  from distutils.version import LooseVersion
  from io import StringIO
  import matplotlib
  import matplotlib.pyplot
  import sphinx
  from .None import glr_path_static
  from .None import sphinx_compatibility
  from .backreferences import write_backreferences, _thumbnail_div
  from .downloads import CODE_DOWNLOAD
  from .py_source_parser import split_code_and_text_blocks
  from .notebook import jupyter_notebook, save_notebook
label_desc: Use image node_id 5 for calling a global function with example usage: save_figures(image_path, fig_count, gallery_conf) and returns: figure_rst