Created
October 8, 2014 06:49
-
-
Save sangheestyle/b96da7c313f3e486b2a9 to your computer and use it in GitHub Desktop.
snippets for Networkx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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