code: def write_figure_classes(
      outdir,
      trace_node,
      data_validator,
      layout_validator,
      frame_validator,
      subplot_nodes,
      layout_array_nodes,
  ):
      """
      Construct source code for the Figure and FigureWidget classes and
      write to graph_objs/_figure.py and graph_objs/_figurewidget.py
      respectively
  
      Parameters
      ----------
      outdir : str
          Root outdir in which the graph_objs package should reside
      trace_node : PlotlyNode
          Root trace node (the node that is the parent of all of the
          individual trace nodes like bar, scatter, etc.)
      data_validator : BaseDataValidator
          DataValidator instance
      layout_validator : CompoundValidator
          LayoutValidator instance
      frame_validator : CompoundArrayValidator
          FrameValidator instance
      subplot_nodes: list of PlotlyNode
          List of names of all of the layout subplot properties
      layout_array_nodes: list of PlotlyNode
          List of array nodes under layout that can be positioned using xref/yref
      Returns
      -------
      None
      """
  
      # Validate inputs
      # ---------------
      if trace_node.node_path:
          raise ValueError(
              f"Expected root trace node.\n"
              f'Received node with path "{trace_node.path_str}"'
          )
  
      # Loop over figure types
      # ----------------------
      base_figures = [
          ("basewidget", "BaseFigureWidget", "FigureWidget"),
          ("basedatatypes", "BaseFigure", "Figure"),
      ]
  
      for base_package, base_classname, fig_classname in base_figures:
          # ### Build figure source code string ###
          figure_source = build_figure_py(
              trace_node,
              base_package,
              base_classname,
              fig_classname,
              data_validator,
              layout_validator,
              frame_validator,
              subplot_nodes,
              layout_array_nodes,
          )
  
          # ### Format and write to file###
          filepath = opath.join(
              outdir, "graph_objs", f"_{fig_classname.lower()}.py"
          )
          write_source_py(figure_source, filepath)
  
imports: from io import StringIO
  from os import path
  from codegen.datatypes import reindent_validator_description, add_constructor_params, add_docstring
  from codegen.utils import write_source_py
  import inflect
  from plotly.basedatatypes import BaseFigure
label_desc: Use image node_id 2 for calling a global function with example usage: write_figure_classes(outdir, trace_node, data_validator, layout_validator, frame_validator, subplot_nodes, layout_array_nodes) without return types