-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Organising information: graphs", exercise 1 #36
Comments
I looked for a quick and easy way to represent the graph and see if it was correct. I found this: https://www.geeksforgeeks.org/python-visualize-graphs-generated-in-networkx-using-matplotlib/. I also noticed that if you create a connection between two nodes without having created the nodes first, they are created automatically, thus saving you many steps. Is this approach correct @essepuntato? import networkx as nx
import matplotlib.pyplot as plt
tim_berners_lee_network = nx.MultiGraph()
tim_berners_lee_network.add_edge("Tim Berners Lee", "Tom Heath", weight=18)
tim_berners_lee_network.add_edge("Tim Berners Lee", "Christian Bizer", weight=18)
tim_berners_lee_network.add_edge("Tim Berners Lee", "Sören Auer", weight=10)
tim_berners_lee_network.add_edge("Tim Berners Lee", "Lalana Kagal", weight=9)
tim_berners_lee_network.add_edge("Tim Berners Lee", "Daniel J. Weitzner", weight=8)
print(tim_berners_lee_network.nodes())
# ['Tim Berners Lee', 'Tom Heath', 'Christian Bizer', 'Sören Auer', 'Lalana Kagal', 'Daniel J. Weitzner']
print(tim_berners_lee_network.edges(data=True))
# [('Tim Berners Lee', 'Tom Heath', {'weight': 18}), ('Tim Berners Lee', 'Christian Bizer', {'weight': 18}), ('Tim Berners Lee', 'Sören Auer', {'weight': 10}), ('Tim Berners Lee', 'Lalana Kagal', {'weight': 9}), ('Tim Berners Lee', 'Daniel J. Weitzner', {'weight': 8})]
nx.draw(tim_berners_lee_network, with_labels = True)
plt.savefig("filename.png") |
|
Consider the list of co-authors of Tim Berners-Lee as illustrated in the right box at http://dblp.uni-trier.de/pers/hd/b/Berners=Lee:Tim. Build an undirected graph that contains Tim Berners Lee as the central node, and that links to five nodes representing his top-five co-authors. Also, specify the weight of each edge as an attribute, where the value of the weight is the number of bibliographic resources (articles, proceedings, etc.) Tim Berners-Lee has co-authored with the person linked by that edge.
The text was updated successfully, but these errors were encountered: