Open schatzsc opened 1 year ago
Some quick and dirty code how to pass on element_color
to nx.kamada_kawai_layout(G)
:
node_color_list = []
for i in G:
element_color = G.nodes.data('element_color')[i]
if element_color == "lightgrey":
element_color = "0xD3D3D3"
color_code = '#'+element_color[2:]
node_color_list.append(color_code)
node_size = 1 / G.order() * 10000
options = { "with_labels": False, "font_size": 18, "node_size": node_size, "edgecolors": "black", "linewidths": 2, "width": 2, "node_color": node_color_list }
positions = nx.kamada_kawai_layout(G)
pos_attrs = {}
for node, coords in positions.items():
pos_attrs[node] = (coords[0], coords[1])
node_attrs1 = nx.get_node_attributes(G, 'element_symbol')
node_attrs2 = nx.get_node_attributes(G, 'atomic_number')
custom_node_attrs1 = {}
custom_node_attrs2 = {}
for node, attr in node_attrs1.items():
custom_node_attrs1[node] = str(node)
custom_node_attrs2[node] = attr
for node, attr in node_attrs2.items():
custom_node_attrs2[node] = custom_node_attrs2[node]+"\n"+str(attr)
nx.draw(G, positions, **options)
Originally posted by @JanCBrammer in https://github.com/TUCAN-nest/TUCAN/issues/81#issuecomment-1278559443