Avoid labels being cut at the edges in NetworkX

后端 未结 1 795
隐瞒了意图╮
隐瞒了意图╮ 2021-01-22 10:21

I am using python networkx lib draw a node relation graph. Code like this:

import networkx as nx 
import matplotlib.pyplot as plt

G = nx.Graph()
G.add_edges_fro         


        
相关标签:
1条回答
  • 2021-01-22 10:47

    You could set the scale parameter in nx.spring_layout to a low value to scale down the positions. It basically applies a scale factor to the node positions, so the nodes are positioned in a box of size [0,scale]. Here's an example:

    pos = nx.spring_layout(G, scale=0.2)
    nx.draw_networkx_nodes(G,pos)
    nx.draw_networkx_edges(G,pos)
    y_off = 0.02
    nx.draw_networkx_labels(G, pos = {k:([v[0], v[1]+y_off]) for k,v in pos.items()})
    

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