Position/showing of labels with networkx + graphviz

前端 未结 1 655
一向
一向 2021-01-15 01:49

I\'ve achieved the following plot with a combination networkx and graphviz:

I\'m very happy with the result. In the plot you can identify what I call aggreg

相关标签:
1条回答
  • 2021-01-15 02:08

    Ok, so I've partially solved the second question: how to plot from the aggregation nodes onwards. To do so I estimate the number of hops towards the latest one. After that I decide to label the nodes below the threshold.

    def getHopToNH(nodes):
        path        = []
        labelList   = {}
    
        for startNode in G.nodes():
            endNode = 'myLabel'
            try:
                p = len(nx.shortest_path(G,source=startNode,target=endNode))
            except:
                p = -1
            path.append((startNode,p))
    
            if p < 8:
                labelList = {**labelList,**{str(startNode):str(startNode)}}
            else:
                labelList = {**labelList,**{str(startNode):''}}
    
        return labelList
    

    UPDATE:

    Now, in order to re-position the labels, I had to modify the position myself.

    for p in pos:
    
        yOffSet = -300
        xOffSet = -400
    
        pos[p] = (pos[p][0]+xOffSet,pos[p][1]+yOffSet)
    
    labelDescr = nx.draw_networkx_labels(G,
        pos         = pos,
        labels      = nodeLabelDict,
        font_size   = nodeFontSize,)
    
    for n,t in labelDescr.items():
        finDegree = 70
        t.set_rotation(finDegree)
    

    After this, I get to plot the following:

    And I really like this output now ... :-)

    0 讨论(0)
提交回复
热议问题