1

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) NCAA "March Madness" bracket
(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. img

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)    
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
NumericOverflow
  • 899
  • 8
  • 17
  • 1
    It would be fairly simple to just define the node positions yourself rather than using a built-in code. – Joel Mar 08 '16 at 12:07
  • @Joel - How would I do that or where do I pass them? I'm assuming your talking about "pointList" in graphviz, but I can't seem to find a good example of how exactly to accomplish this. Maybe my google-fu is just off base. – NumericOverflow Mar 10 '16 at 21:02
  • Look at what `pos` is defined to be (print it out) - it's a dictionary giving the positions of each node. So you could define that. It'll still take a bit of work, but there's not going to be anything built in to do such a specialized arrangement. – Joel Mar 11 '16 at 01:04

0 Answers0