I'm trying to visualize a tournament directed graph I have in python as a networkx object. Ideally, it would be great if I could visualize it similar to the classic NCAA "March Madness" bracket. The closest I've come so far, is using a dot layout, but it's not very intuitive and doesn't look like the bracket much at all.
I've got a single graph, but could break it into 4 subgraphs (the way march madness is setup) if that made visualization better.
Here's an example of the layout I'm looking for (or something near it)
(source: shorebranding.com)
Here's what I've gotten so far, it needs refinement, but you get the idea that it's a poor representation of the graph.
Here's a bit of the code I'm using now to build & output the graph to an image:
def buildTourneyGraph(games,analysisYear):
MG=nx.DiGraph()
#for idx, gm in enumerate(games): # Iterate through rows
for gm in games: # Iterate through rows
#pp.pprint(gm)
if gm["academicYear".upper()] == int(analysisYear):
#add the two team nodes
MG.add_node(gm["winner".upper()])
MG.add_node(gm["loser".upper()])
MG.add_edge(gm["loser".upper()], gm["winner".upper()], weight=gm["margin".upper()] , round=gm["round".upper()])
#Draw a graph and save it to a PNG file
#nx.draw_spectral(MG)
#nx.draw_graphviz(MG)
#nx.draw_shell(MG)
# same layout using matplotlib with labels
plt.title("NCAA Tourney for " + str(analysisYear))
pos=nx.graphviz_layout(MG,prog='dot')
nx.draw(MG,pos,with_labels=True,arrows=True,node_size=20,node_color="red")
outputGraphFile = os.path.expanduser('C:/Users/myUser/Documents/graph_tourney_' + str(analysisYear) + '.png')
plt.savefig(outputGraphFile)