如何使用networkx获得节点的线边界?见下图。我的问题是由于白色节点造成的。我想展示它们的形状,无论颜色如何。请参阅节点 4 与其他节点的比较。
代码示例
import networkx as nx
import matplotlib.pyplot as plot
g= {1: [2, 3],
2: [2, 3, 4],
3: [1, 2],
4: [2]}
graph= nx.Graph()
for v in g:
graph.add_node(v)
for v in g:
for u in g[v]:
graph.add_edge(v, u)
nx.draw_networkx(graph, node_color=['r', 'r', 'r', 'w'], node_shape='o')
plot.axis('off')
plot.show()
输出
最佳答案
我明白了。
ax= plot.gca()
ax.collections[0].set_edgecolor("#000000")
在上面添加线条以设置节点边缘的颜色。
import networkx as nx
import matplotlib.pyplot as plot
g= {1: [2, 3],
2: [2, 3, 4],
3: [1, 2],
4: [2]}
graph= nx.Graph()
for v in g:
graph.add_node(v)
for u in g[v]:
graph.add_edge(v, u)
nx.draw_networkx(graph, node_color=['r', 'r', 'r', 'w'], node_shape='o')
ax= plot.gca()
ax.collections[0].set_edgecolor("#000000")
plot.axis('off')
plot.show()
关于python - python网络中的节点没有边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874397/