code: def figure(key=None, fig=None, **kwargs):
      """Creates figures and switches between figures.
  
      If a ``bqplot.Figure`` object is provided via the fig optional argument,
      this figure becomes the current context figure.
  
      Otherwise:
  
      - If no key is provided, a new empty context figure is created.
      - If a key is provided for which a context already exists, the
        corresponding context becomes current.
      - If a key is provided and no corresponding context exists, a new context
        is reated for that key and becomes current.
  
      Besides, optional arguments allow to set or modify Attributes
      of the selected context figure.
  
      Parameters
      ----------
      key: hashable, optional
          Any variable that can be used as a key for a dictionary
      fig: Figure, optional
          A bqplot Figure
  
      """
      scales_arg = kwargs.pop("scales", {})
      _context["current_key"] = key
      if fig is not None:  # fig provided
          _context["figure"] = fig
          if key is not None:
              _context["figure_registry"][key] = fig
          for arg in kwargs:
              setattr(_context["figure"], arg, kwargs[arg])
      else:  # no fig provided
          if key is None:  # no key provided
              _context["figure"] = Figure(**kwargs)
          else:  # a key is provided
              if key not in _context["figure_registry"]:
                  if "title" not in kwargs:
                      kwargs["title"] = "Figure" + " " + str(key)
                  _context["figure_registry"][key] = Figure(**kwargs)
              _context["figure"] = _context["figure_registry"][key]
              for arg in kwargs:
                  setattr(_context["figure"], arg, kwargs[arg])
      scales(key, scales=scales_arg)
      # Set the axis reference dictionary. This dictionary contains the mapping
      # from the possible dimensions in the figure to the list of scales with
      # respect to which axes have been drawn for this figure.
      # Used to automatically generate axis.
      if getattr(_context["figure"], "axis_registry", None) is None:
          setattr(_context["figure"], "axis_registry", {})
      return _context["figure"]
  
imports: import sys
  from collections import OrderedDict
  from IPython.display import display
  from ipywidgets import Image
  from numpy import arange, issubdtype, array, column_stack, shape
  from .figure import Figure
  from bqscales import Scale, LinearScale, Mercator
  from .axes import Axis
  from .marks import Lines, Scatter, Hist, Bars, OHLC, Pie, Map, Image, Label, HeatMap, GridHeatMap, topo_load, Boxplot, Bins
  from .interacts import BrushIntervalSelector, FastIntervalSelector, BrushSelector, IndexSelector, MultiSelector, LassoSelector
  from traitlets.utils.sentinel import Sentinel
  import functools
label_desc: Use image node_id 3 for calling a global function with example usage: figure(key, fig) and returns: _context