python script to generate graph with subgraphs