code: def add_parser(subparsers, parent_parser):
      PLOTS_HELP = "Commands to visualize and compare plot data."
  
      plots_parser = subparsers.add_parser(
          "plots",
          parents=[parent_parser],
          description=append_doc_link(PLOTS_HELP, "plots"),
          help=PLOTS_HELP,
          formatter_class=formatter.RawDescriptionHelpFormatter,
      )
      plots_subparsers = plots_parser.add_subparsers(
          dest="cmd",
          help="Use `dvc plots CMD --help` to display command-specific help.",
          required=True,
      )
  
      SHOW_HELP = "Generate plots from target files or from `plots` definitions in `dvc.yaml`."
      plots_show_parser = plots_subparsers.add_parser(
          "show",
          parents=[parent_parser],
          description=append_doc_link(SHOW_HELP, "plots/show"),
          help=SHOW_HELP,
          formatter_class=formatter.RawDescriptionHelpFormatter,
      )
      plots_show_parser.add_argument(
          "targets",
          nargs="*",
          help=(
              "Plots files or plot IDs from `dvc.yaml` to visualize. "
              "Shows all plots by default."
          ),
      ).complete = completion.FILE
      _add_props_arguments(plots_show_parser)
      _add_output_argument(plots_show_parser)
      _add_ui_arguments(plots_show_parser)
      plots_show_parser.set_defaults(func=CmdPlotsShow)
  
      PLOTS_DIFF_HELP = "Show multiple versions of a plot by overlaying them in a single image."
      plots_diff_parser = plots_subparsers.add_parser(
          "diff",
          parents=[parent_parser],
          description=append_doc_link(PLOTS_DIFF_HELP, "plots/diff"),
          help=PLOTS_DIFF_HELP,
          formatter_class=formatter.RawDescriptionHelpFormatter,
      )
      plots_diff_parser.add_argument(
          "--targets",
          nargs="*",
          help=(
              "Specific plots to visualize. "
              "Accepts any file path or plot name from `dvc.yaml` file. "
              "Shows all tracked plots by default."
          ),
          metavar="<paths>",
      ).complete = completion.FILE
      plots_diff_parser.add_argument(
          "-e",
          "--experiment",
          action="store_true",
          default=False,
          help=argparse.SUPPRESS,
      )
      plots_diff_parser.add_argument(
          "revisions",
          nargs="*",
          default=None,
          help="Git commits to plot from",
      )
      _add_props_arguments(plots_diff_parser)
      _add_output_argument(plots_diff_parser)
      _add_ui_arguments(plots_diff_parser)
      plots_diff_parser.set_defaults(func=CmdPlotsDiff)
  
      PLOTS_MODIFY_HELP = (
          "Modify display properties of data-series plots "
          "defined in stages (has no effect on image plots)."
      )
      plots_modify_parser = plots_subparsers.add_parser(
          "modify",
          parents=[parent_parser],
          description=append_doc_link(
              PLOTS_MODIFY_HELP, "plots/modify"
          ),
          help=PLOTS_MODIFY_HELP,
          formatter_class=formatter.RawDescriptionHelpFormatter,
      )
      plots_modify_parser.add_argument(
          "target",
          help="Plots file to set properties for (defined at the stage level).",
      ).complete = completion.FILE
      _add_props_arguments(plots_modify_parser)
      plots_modify_parser.add_argument(
          "--unset",
          nargs="*",
          metavar="<property>",
          help="Unset one or more display properties.",
      )
      plots_modify_parser.set_defaults(func=CmdPlotsModify)
  
      TEMPLATES_HELP = "List built-in plots templates or show JSON specification for one."
      plots_templates_parser = plots_subparsers.add_parser(
          "templates",
          parents=[parent_parser],
          description=append_doc_link(
              TEMPLATES_HELP, "plots/templates"
          ),
          help=TEMPLATES_HELP,
          formatter_class=formatter.RawDescriptionHelpFormatter,
      )
      plots_templates_parser.add_argument(
          "template",
          default=None,
          nargs="?",
          help=(
              "Template for which to show JSON specification. "
              "List all template names by default."
          ),
      )
      plots_templates_parser.set_defaults(func=CmdPlotsTemplates)
  
imports: import argparse
  import os
  from typing import TYPE_CHECKING, Dict, List, Optional
  from funcy import compact, first, get_in
  from dvc.cli import completion, formatter
  from dvc.cli.command import CmdBase
  from dvc.cli.utils import append_doc_link
  from dvc.exceptions import DvcException
  from dvc.log import logger
  from dvc.ui import ui
  from dvc.utils import format_link
label_desc: Use image node_id 2 for calling a global function with example usage: add_parser(subparsers, parent_parser) without return types