pygraphviz show
To display a graph using pygraphviz, you can follow these steps:
- Import the necessary modules:
import pygraphviz as pgv
- Create a new graph object:
G = pgv.AGraph()
- Add nodes to the graph:
G.add_node('Node1')
G.add_node('Node2')
- Add edges between the nodes:
G.add_edge('Node1', 'Node2')
- 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'
- Display the graph:
G.draw('graph.png', prog='dot')
- Optionally, show the graph using a viewer:
G.draw('graph.png', prog='dot')
G.show('graph.png')