如何使 NetworkX 图形可视化更具可读性?
How to make a NetworkX graph visualization more readable?
如何让下图更显眼。有两个问题。蓝点是如此之小,我需要一种方法来使点的大小足够大以包括最大的标签(以及所有其他标签)。另一方面,一些边缘太短。如何解决?
我用来创建此图表的代码是:
nx.draw(graph, pos = nx.spring_layout(graph), with_labels = True)
对于节点间距,nx.spring_layout
has a parameter (k
) to adjust the spacing between nodes, the higher the more spacing. For the other parameters, you could improve the graph visibility by reducing the edge width and also by increasing the node size using the corresponding parameters in nx.draw
。这是一个使用随机图的示例:
from matplotlib import pyplot as plt
G = nx.fast_gnp_random_graph(100, .05)
plt.figure(figsize=(10,6))
pos = nx.spring_layout(G, k=0.8)
nx.draw(G, pos , with_labels = True, width=0.4,
node_color='lightblue', node_size=400)
如何让下图更显眼。有两个问题。蓝点是如此之小,我需要一种方法来使点的大小足够大以包括最大的标签(以及所有其他标签)。另一方面,一些边缘太短。如何解决?
我用来创建此图表的代码是:
nx.draw(graph, pos = nx.spring_layout(graph), with_labels = True)
对于节点间距,nx.spring_layout
has a parameter (k
) to adjust the spacing between nodes, the higher the more spacing. For the other parameters, you could improve the graph visibility by reducing the edge width and also by increasing the node size using the corresponding parameters in nx.draw
。这是一个使用随机图的示例:
from matplotlib import pyplot as plt
G = nx.fast_gnp_random_graph(100, .05)
plt.figure(figsize=(10,6))
pos = nx.spring_layout(G, k=0.8)
nx.draw(G, pos , with_labels = True, width=0.4,
node_color='lightblue', node_size=400)