code: def plot(dag: DAGNode, to_file=None):
      if to_file is None:
          tmp_file = tempfile.NamedTemporaryFile(suffix=".png")
          to_file = tmp_file.name
          extension = "png"
      else:
          _, extension = os.path.splitext(to_file)
          if not extension:
              extension = "png"
          else:
              extension = extension[1:]
  
      graph = _dag_to_dot(dag)
      graph.write(to_file, format=extension)
  
      # Render the image directly if running inside a Jupyter notebook
      try:
          from IPython import display
  
          return display.Image(filename=to_file)
      except ImportError:
          pass
  
      # close temp file if needed
      try:
          tmp_file.close()
      except NameError:
          pass
  
file_path: ray/python/ray/dag/vis_utils.py
imports: from ray.dag import DAGNode
  import os
  import tempfile
  from ray.dag.utils import _DAGNodeNameGenerator
  from ray.util.annotations import DeveloperAPI
label_desc: Use image node_id 1 for calling a global function with example usage: plot(dag, to_file) and returns: display