Skip to content

Instantly share code, notes, and snippets.

@sangheestyle
Created October 8, 2014 06:49
Show Gist options
  • Save sangheestyle/b96da7c313f3e486b2a9 to your computer and use it in GitHub Desktop.
Save sangheestyle/b96da7c313f3e486b2a9 to your computer and use it in GitHub Desktop.
snippets for Networkx
# origin: http://stackoverflow.com/questions/24662006/python-networkx-graph-different-colored-nodes-using-two-lists
## assign a node attribute, which I am going to color according to
for node in G.nodes():
G.node[node]['category'] = my_category_dict[node]
## put together a color map, one color for a category
color_map = {'type_A':'b', 'type_B':'#FF0099', 'type_C':'#660066'}
## construct a list of colors then pass to node_color
nx.draw(G, node_color=[color_map[G.node[node]['category']] for node in G])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment