code: def populate_examples(**kwds):
      """Iterate through Altair examples and extract code"""
  
      examples = sorted(
          iter_examples_arguments_syntax(), key=itemgetter("name")
      )
      method_examples = {
          x["name"]: x for x in iter_examples_methods_syntax()
      }
  
      for example in examples:
          docstring, category, code, lineno = get_docstring_and_rest(
              example["filename"]
          )
          if example["name"] in method_examples.keys():
              _, _, method_code, _ = get_docstring_and_rest(
                  method_examples[example["name"]]["filename"]
              )
          else:
              method_code = code
              code += (
                  "# No channel encoding options are specified in this chart\n"
                  "# so the code is the same as for the method-based syntax.\n"
              )
          example.update(kwds)
          if category is None:
              raise Exception(
                  f"The example {example['name']} is not assigned to a category"
              )
          example.update(
              {
                  "docstring": docstring,
                  "title": docstring.strip().split("\n")[0],
                  "code": code,
                  "method_code": method_code,
                  "category": category.title(),
                  "lineno": lineno,
              }
          )
  
      return examples
  
imports: import hashlib
  import os
  import json
  import random
  import collections
  from operator import itemgetter
  import warnings
  import shutil
  import jinja2
  from docutils import nodes
  from docutils.statemachine import ViewList
  from docutils.parsers.rst import Directive
  from docutils.parsers.rst.directives import flag
  from sphinx.util.nodes import nested_parse_with_titles
  from .utils import get_docstring_and_rest, prev_this_next, create_thumbnail, create_generic_image
  from altair.utils.execeval import eval_block
  from tests.examples_arguments_syntax import iter_examples_arguments_syntax
  from tests.examples_methods_syntax import iter_examples_methods_syntax
label_desc: Use image node_id 2 for calling a global function with example usage: populate_examples() and returns: examples