1

我正在尝试将我在 python 中的锦标赛有向图可视化为 networkx 对象。理想情况下,如果我能将其可视化为类似于经典的 NCAA“疯狂三月”支架,那就太好了。到目前为止,我最接近的是使用点布局,但它不是很直观,而且看起来一点也不像括号。

我有一个图表,但如果这可以使可视化更好,可以将其分成 4 个子图(设置疯狂行军的方式)。

这是我正在寻找的布局示例(或附近的东西) (来源:shorebranding.comNCAA

这是我到目前为止所得到的,它需要改进,但你会认为它对图表的表示很差。 图像

这是我现在用来构建图形并将其输出到图像的一些代码:

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)    
4

0 回答 0