For a directed networkx graph the data is read from a csv file; The nodes' colours are set by degree of nodes. I want to set each edge line colour to take the node's colour. There has to be an efficient way to access the indices of nodes and respective edges of each node.
Any ideas to achieve this?
current sample data and code as follows:
import networkx as nx
import matplotlib.pylab as plt
import pandas as pd
G = nx.Graph()
edges = [(1, 2, 10), (1, 6, 15), (2, 3, 20), (2, 4, 10),
(2, 6, 20), (3, 4, 30), (3, 5, 15), (4, 8, 20),
(4, 9, 10), (6, 7, 30)]
G.add_weighted_edges_from(edges)
def nodescoldeg(g):
nodecol = [g.degree(u) for u in g]
return nodecol
#edge_colour can be a sequence of colors with the same length as edgelist
def edgecoldeg(g):
nodecol = nodecoldeg(g)
i = 0
for index1, u in enumerate(g.nodes()):
for index2, v in enumerate(nx.dfs_edges(g,u)):
edgecol[i] = nodecol[index1]
i = i+1
#??? edgecol gives out of bound error...
return edgecoldeg
nx.draw(G, node_color=nodecoldeg(G), edge_color=edgecoldeg(G), with_labels=True)