I want to draw a bipartite graph connecting colleagues and moviepreferences. How can I show in the graph both the node name (so the moviename or colleague name) and the node attribute (whether it is a colleague or a movie) in the nodes ?
My current code only displays the node attribute and drops the node name.
My code:
BG = nx.Graph()
BG.add_nodes_from(employees, bipartite=0, _type='employee')
BG.add_nodes_from(movies, bipartite=1, _type='movie')
edgeinfo = pd.read_csv('Employee_Movie_Choices.txt', sep='\t')
edges = [tuple(x) for x in edgeinfo.values]
BG.add_edges_from(edges)
labels = dict((n,d['_type']) for n,d in BG.nodes(data=True))
%matplotlib notebook
import matplotlib.pyplot as plt
plt.figure()
pos = nx.spring_layout(BG)
edges = BG.edges()
nx.draw_networkx(BG, pos, edges=edges, labels=labels)
If I create label tuples, he gives me an error:
BG = nx.Graph()
BG.add_nodes_from(employees, bipartite=0, _type='employee')
BG.add_nodes_from(movies, bipartite=1, _type='movie')
edgeinfo = pd.read_csv('Employee_Movie_Choices.txt', sep='\t')
edges = [tuple(x) for x in edgeinfo.values]
BG.add_edges_from(edges)
labels = dict((n,d['_type']) for n,d in BG.nodes(data=True)) ###ik krijg hier naam movie en employee niet meer bij !!!
labels_new = [(k, v) for k, v in labels.items()]
#labels = [tuple(n,d['_type']) for n, d in BG.nodes(data=True)]
#nx.draw(BG, labels=labels)
%matplotlib notebook
import matplotlib.pyplot as plt
plt.figure()
pos = nx.spring_layout(BG)
edges = BG.edges()
nx.draw_networkx(BG, pos, edges=edges, labels=labels_new)
Error: ---> nx.draw_networkx(BG, pos, edges=edges, labels=labels_new) AttributeError: 'list' object has no attribute 'items'