2

How do I get a line boundary of nodes using networkx? See figure bellow. My problem is due to white colour nodes. I would like to diplay their shapes regardless the colour. See node 4 by comparison with others.

Code example

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

Output

enter image description here

André Gomes
  • 185
  • 13
  • https://stackoverflow.com/q/22716161/2966723 – Joel Jul 02 '17 at 23:52
  • Possible duplicate of [How can one modify the outline color of a node In networkx?](https://stackoverflow.com/questions/22716161/how-can-one-modify-the-outline-color-of-a-node-in-networkx) – Joel Jul 03 '17 at 05:47

1 Answers1

5

I got it.

ax= plot.gca()
ax.collections[0].set_edgecolor("#000000")

Add lines above in order to set colours of nodes' edges.

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()
André Gomes
  • 185
  • 13