'How to set colors for nodes in NetworkX?
I created my graph, everything looks great so far, but I want to update color of my nodes after creation.
My goal is to visualize DFS, I will first show the initial graph and then color nodes step by step as DFS solves the problem.
If anyone is interested, sample code is available on Github
Solution 1:[1]
Refer to node_color parameter:
nx.draw_networkx_nodes(G, pos, node_size=200, node_color='#00b4d9')
Solution 2:[2]
has been answered before, but u can do this as well:
# define color map. user_node = red, book_nodes = green
color_map = ['red' if node == user_id else 'green' for node in G]
graph = nx.draw_networkx(G,pos, node_color=color_map) # node lables
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Montenegrodr |
| Solution 2 | Qasim Wani |
