code: def to_agraph(self):
          
          A = nx.nx_agraph.to_agraph(self)
          A.graph_attr.update(
              {"dpi": 227, "fontsize": 20, "fontname": "Menlo", "rankdir": "TB"}
          )
          A.node_attr.update({"fontname": "Menlo"})
  
          def build_tree(cluster_name, root_graph):
              subgraph_nodes = [
                  n[0]
                  for n in self.nodes(data=True)
                  if n[1]["parent"] == cluster_name
              ]
              root_graph.add_nodes_from(subgraph_nodes)
              subgraph = root_graph.add_subgraph(
                  subgraph_nodes,
                  name=f"cluster_{cluster_name}",
                  label=cluster_name,
                  style="bold, rounded",
              )
              for n in self.scope_tree.successors(cluster_name):
                  build_tree(n, subgraph)
  
          root = [n for n, d in self.scope_tree.in_degree() if d == 0][0]
          build_tree(root, A)
          return A
docs: Export to a PyGraphviz AGraph object.