comp-think / 2022-2023

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2022/2023).
17 stars 5 forks source link

Lecture "Organising information: graphs", exercise 2 #36

Open essepuntato opened 1 year ago

essepuntato commented 1 year ago

Create a directed graph that relates the actors Brad Pitt, Eva Green, George Clooney, Catherine Zeta-Jones, Johnny Depp, and Helena Bonham Carter to the following movies: Ocean's Twelve, Fight Club, Dark Shadows.

alka2696 commented 1 year ago
from networkx import DiGrapgh

my_graph = DiGrapgh()

my_graph.add_node("Brad Pitt")
my_graph.add_node("Eva Green")
my_graph.add_node("George Clooney")
my_graph.add_node("Catherine Zeta-Jones")
my_graph.add_node("Johnny Depp")
my_graph.add_node("Helena Bonham Carter")
my_graph.add_node("Ocean's Twelve")
my_graph.add_node("Fight Club")
my_graph.add_node("Dark Shadows")

my_graph.add_edge("Brad Pitt", "Ocean's Twelve")
my_graph.add_edge("George Clooney", "Ocean's Twelve")
my_graph.add_edge("Catherine Zeta-Jones", "Ocean's Twelve")

my_graph.add_edge("Brad Pitt", "Fight Club")
my_graph.add_edge("Helena Bonham Carter", "Fight Club")

my_graph.add_edge("Helena Bonham Carter", "Dark Shadows")
my_graph.add_edge("Johnny Depp", "Dark Shadows")
my_graph.add_edge("Eva Green", "Dark Shadows")
EricaAndreose commented 1 year ago
from networkx import DiGraph

movie_graph = DiGraph()

movie_graph.add_node("Brad Pitt")
movie_graph.add_node("Eva Green")
movie_graph.add_node("George Clooney")
movie_graph.add_node("Catherine Zeta-Jones")
movie_graph.add_node("Johnny Depp")
movie_graph.add_node("Helena Bonham Carter")
movie_graph.add_node("Ocean's Twelve")
movie_graph.add_node("Fight Club")
movie_graph.add_node("Dark Shadows")

movie_graph.add_edge("George Clooney", "Ocean's Twelve")
movie_graph.add_edge("Brad Pitt", "Ocean's Twelve")
movie_graph.add_edge("Catherine Zeta-Jones", "Ocean's Twelve")
movie_graph.add_edge("Brad Pitt", "Fight Club")
movie_graph.add_edge("Helena Bonham Carter", "Fight Club")
movie_graph.add_edge("Johnny Depp", "Dark Shadows")
movie_graph.add_edge("Helena Bonham Carter", "Dark Shadows")
movie_graph.add_edge("Eva Green", "Dark Shadows")

I've also tried to visualize it using matplotlib and this is the result: Figure_1