code: def vars_to_plot(
      self, var_names: Optional[Iterable[VarName]] = None
  ) -> List[VarName]:
      if var_names is None:
          return self._all_var_names
  
      selected_names = set(var_names)
  
      # .copy() because sets cannot change in size during iteration
      for var_name in selected_names.copy():
          if var_name not in self._all_var_names:
              raise ValueError(f"{var_name} is not in this model.")
  
          for model_var in self.var_list:
              if model_var in self.model.observed_RVs:
                  if (
                      self.model.rvs_to_values[model_var]
                      == self.model[var_name]
                  ):
                      selected_names.add(model_var.name)
  
      selected_ancestors = set(
          filter(
              lambda rv: rv.name in self._all_var_names,
              list(
                  ancestors(
                      [
                          self.model[var_name]
                          for var_name in selected_names
                      ]
                  )
              ),
          )
      )
  
      for var in selected_ancestors.copy():
          if var in self.model.observed_RVs:
              selected_ancestors.add(self.model.rvs_to_values[var])
  
      # ordering of self._all_var_names is important
      return [get_var_name(var) for var in selected_ancestors]
  
imports: import warnings
  from collections import defaultdict
  from typing import Dict, Iterable, List, Optional, Sequence, Set
  from pytensor import function
  from pytensor.compile.sharedvalue import SharedVariable
  from pytensor.graph import Apply
  from pytensor.graph.basic import ancestors, walk
  from pytensor.scalar.basic import Cast
  from pytensor.tensor.elemwise import Elemwise
  from pytensor.tensor.random.op import RandomVariable
  from pytensor.tensor.shape import Shape
  from pytensor.tensor.variable import TensorConstant, TensorVariable
  import pymc
  from pymc.util import VarName, get_default_varnames, get_var_name
label_desc: Use image node_id 3 for calling the ModelGraph obj's underlying member method code with example usage: obj.vars_to_plot(var_names) and returns: unknown, self