pygraphviz show

To display a graph using pygraphviz, you can follow these steps:

  1. Import the necessary modules:
import pygraphviz as pgv
  1. Create a new graph object:
G = pgv.AGraph()
  1. Add nodes to the graph:
G.add_node('Node1')
G.add_node('Node2')
  1. Add edges between the nodes:
G.add_edge('Node1', 'Node2')
  1. Set properties for the nodes and edges:
G.get_node('Node1').attr['shape'] = 'circle'
G.get_node('Node2').attr['shape'] = 'square'
G.get_edge('Node1', 'Node2').attr['color'] = 'red'
  1. Display the graph:
G.draw('graph.png', prog='dot')
  1. Optionally, show the graph using a viewer:
G.draw('graph.png', prog='dot')
G.show('graph.png')