code: def run_code(code, code_path, ns=None):
      # Change the working directory to the directory of the example, so
      # it can get at its data files, if any.
      pwd = os.getcwd()
      old_sys_path = list(sys.path)
      if code_path is not None:
          dirname = os.path.abspath(os.path.dirname(code_path))
          os.chdir(dirname)
          sys.path.insert(0, dirname)
  
      # Redirect stdout
      stdout = sys.stdout
      sys.stdout = StringIO()
  
      # Reset sys.argv
      old_sys_argv = sys.argv
      sys.argv = [code_path]
  
      try:
          try:
              code = unescape_doctest(code)
              if ns is None:
                  ns = {}
              if not ns:
                  exec(setup.config.plot_pre_code, ns)
              exec(code, ns)
          except (Exception, SystemExit) as err:
              raise PlotError(traceback.format_exc())
      finally:
          os.chdir(pwd)
          sys.argv = old_sys_argv
          sys.path[:] = old_sys_path
          sys.stdout = stdout
      return ns
  
imports: from __future__ import division, absolute_import, print_function
  import sys, os, glob, shutil, imp, warnings, re, textwrap, traceback
  import sphinx
  import warnings
  from docutils.parsers.rst import directives
  from docutils import nodes
  from docutils import nodes, utils
  import matplotlib
  import matplotlib.pyplot
  import matplotlib.image
  from matplotlib import _pylab_helpers
  import exceptions
label_desc: Use image node_id 10 for calling a global function with example usage: run_code(code, code_path, ns) and returns: ns