code: def pygraphviz_layout(G, prog="neato", root=None, args=""):
      """Create node positions for G using Graphviz.
  
      Parameters
      ----------
      G : NetworkX graph
        A graph created with NetworkX
      prog : string
        Name of Graphviz layout program
      root : string, optional
        Root node for twopi layout
      args : string, optional
        Extra arguments to Graphviz layout program
  
      Returns
      -------
      node_pos : dict
        Dictionary of x, y, positions keyed by node.
  
      Examples
      --------
      >>> G = nx.petersen_graph()
      >>> pos = nx.nx_agraph.graphviz_layout(G)
      >>> pos = nx.nx_agraph.graphviz_layout(G, prog="dot")
  
      Notes
      -----
      If you use complex node objects, they may have the same string
      representation and GraphViz could treat them as the same node.
      The layout may assign both nodes a single location. See Issue #1568
      If this occurs in your case, consider relabeling the nodes just
      for the layout computation using something similar to::
  
          >>> H = nx.convert_node_labels_to_integers(G, label_attribute="node_label")
          >>> H_layout = nx.nx_agraph.pygraphviz_layout(G, prog="dot")
          >>> G_layout = {H.nodes[n]["node_label"]: p for n, p in H_layout.items()}
  
      Note that some graphviz layouts are not guaranteed to be deterministic,
      see https://gitlab.com/graphviz/graphviz/-/issues/1767 for more info.
      """
      try:
          import pygraphviz
      except ImportError as err:
          raise ImportError(
              "requires pygraphviz http://pygraphviz.github.io/"
          ) from err
      if root is not None:
          args += f"-Groot={root}"
      A = to_agraph(G)
      A.layout(prog=prog, args=args)
      node_pos = {}
      for n in G:
          node = pygraphviz.Node(A, n)
          try:
              xs = node.attr["pos"].split(",")
              node_pos[n] = tuple(float(x) for x in xs)
          except:
              print("no position for node", n)
              node_pos[n] = (0.0, 0.0)
      return node_pos
  
file_path: networkx/networkx/drawing/nx_agraph.py
imports: import os
  import tempfile
  import networkx
label_desc: Use image node_id 6 for calling a global function with example usage: pygraphviz_layout(G, prog, root, args) and returns: node_pos