Skip to content
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 2 #36

Open
essepuntato opened this issue Dec 19, 2022 · 2 comments
Open

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

essepuntato opened this issue Dec 19, 2022 · 2 comments
Labels

Comments

@essepuntato
Copy link
Contributor

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
Copy link

alka2696 commented Dec 19, 2022

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants