Code Monkey home page Code Monkey logo

Comments (12)

SeverinJB avatar SeverinJB commented on June 3, 2024 1
from networkx import MultiDiGraph

movie_graph = MultiDiGraph()

# Actors
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")

# Movies
movie_graph.add_node("Ocean's Twelve")
movie_graph.add_node("Fight Club")
movie_graph.add_node("Dark Shadows")

# Cast 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("George Clooney", "Ocean's Twelve")

# Cast Fight Club
movie_graph.add_edge("Brad Pitt", "Fight Club")
movie_graph.add_edge("Helena Bonham Carter", "Fight Club")

# Cast Dark Shadows
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")

print(movie_graph.nodes())
print(movie_graph.edges())

from 2018-2019.

EleonoraPeruch avatar EleonoraPeruch commented on June 3, 2024 1
# Ocean's Twelve
# George Clooney
# Brad Pitt
# Catherine Zeta-Jones

# Fight Club
# Brad Pitt
# Helena Bonham Carter

# Dark Shadows
# Johnny Depp
# Helena Bonham Carter
# Eva Green

from networkx import DiGraph

# create a new graph
actor_and_movie = DiGraph() # I use DiGraph since there is only one edge between each two nodes

# create nodes for actors
actor_and_movie.add_node("Brad Pitt")
actor_and_movie.add_node("Eva Green")
actor_and_movie.add_node("George Clooney")
actor_and_movie.add_node("Catherine Zeta-Jones")
actor_and_movie.add_node("Johnny Depp")
actor_and_movie.add_node("Helena Bonham Carter")

# create nodes for movies
actor_and_movie.add_node("Ocean's Twelve")
actor_and_movie.add_node("Fight Club")
actor_and_movie.add_node("Dark Shadows")

# create edges between each actor and the movies in which he acted
actor_and_movie.add_edge("Brad Pitt", "Ocean's Twelve")
actor_and_movie.add_edge("Brad Pitt", "Fight Club")
actor_and_movie.add_edge("Eva Green", "Dark Shadows")
actor_and_movie.add_edge("George Clooney", "Ocean's Twelve")
actor_and_movie.add_edge("Catherine Zeta-Jones","Ocean's Twelve")
actor_and_movie.add_edge("Johnny Depp", "Dark Shadows")
actor_and_movie.add_edge("Helena Bonham Carter", "Fight Club")
actor_and_movie.add_edge("Helena Bonham Carter", "Dark Shadows")

print(actor_and_movie.nodes())
print(actor_and_movie.edges())

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

from 2018-2019.

andreamust avatar andreamust commented on June 3, 2024 1

from networkx import MultiDiGraph

my_cinema_graph = MultiDiGraph()

my_cinema_graph.add_node(1, name = "Brad", surname = "Pitt")
my_cinema_graph.add_node(2, name = "Eva", surname = "Green")
my_cinema_graph.add_node(3, name = "George", surname = "Clooney")
my_cinema_graph.add_node(4, name = "Catherine", surname = "Zeta-Jones")
my_cinema_graph.add_node(5, name = "Johnny", surname = "Depp")
my_cinema_graph.add_node(6, name = "Helena", surname = "Bohnam Carter")

my_cinema_graph.add_node('x', title = "Ocean's Twelve")
my_cinema_graph.add_node('y', title = "Fight Club")
my_cinema_graph.add_node('z', title = "Dark Shadows")


my_cinema_graph.add_edge(1, 'x')
my_cinema_graph.add_edge(1, 'y')
my_cinema_graph.add_edge(2, 'z')
my_cinema_graph.add_edge(3, 'x')
my_cinema_graph.add_edge(4, 'x')
my_cinema_graph.add_edge(5, 'z')
my_cinema_graph.add_edge(6, 'y')
my_cinema_graph.add_edge(6, 'z')

@essepuntato is there a way to print only the attributes without the node identifiers?

from 2018-2019.

saraarmaroli avatar saraarmaroli commented on June 3, 2024 1

from networkx import DiGraph
actor_movie = DiGraph()

#actors nodes
actor_movie.add_node("Brad Pitt")
actor_movie.add_node("Eva Green")
actor_movie.add_node("George Clooney")
actor_movie.add_node("Catherine Zeta Jones")
actor_movie.add_node("Johnny Depp")
actor_movie.add_node("Helena Bonham Carter")

#movies nodes
actor_movie.add_node("Ocean's Twelve")
actor_movie.add_node("Fight Club")
actor_movie.add_node("Dark Shadows")

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

print(actor_movie.nodes())
print(actor_movie.edges())
['Brad Pitt', 'Eva Green', 'George Clooney', 'Catherine Zeta Jones', 'Johnny Depp', 'Helena Bonham Carter', "Ocean's Twelve", 'Fight Club', 'Dark Shadows', 'Dark Shadow']
[('Brad Pitt', "Ocean's Twelve"), ('Brad Pitt', 'Fight Club'), ('Eva Green', 'Dark Shadows'), ('George Clooney', "Ocean's Twelve"), ('Catherine Zeta Jones', "Ocean's Twelve"), ('Johnny Depp', 'Dark Shadows'), ('Helena Bonham Carter', 'Fight Club'), ('Helena Bonham Carter', 'Dark Shadow')]

from 2018-2019.

lisasiurina avatar lisasiurina commented on June 3, 2024 1
from networkx import DiGraph
movie = DiGraph()

#nodes for actors
movie.add_node("Brad Pitt")
movie.add_node("Eva Green")
movie.add_node("George Clooney")
movie.add_node("Catherine Zeta-Jones")
movie.add_node("Johnny Depp")
movie.add_node("Helena Bonham Carter")

#nodes for movies
movie.add_node("Ocean's Twelve")
movie.add_node("Fight Club")
movie.add_node("Dark Shadows")

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

print(movie.nodes())
print(movie.edges())

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

from 2018-2019.

delfimpandiani avatar delfimpandiani commented on June 3, 2024 1
from networkx import MultiDiGraph

hollywood = MultiDiGraph()

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


print(hollywood.edges())


[('George Clooney', "Ocean's Twelve"), ('Brad Pitt', "Ocean's Twelve"), ('Brad Pitt', 'Fight Club'), ('Catherine Zeta-Jones', "Ocean's Twelve"), ('Helena Bonhan Carter', 'Fight Club'), ('Johny Depp', 'Dark Shadows'), ('Helena Bonham Carter', 'Dark Shadows'), ('Eva Green', 'Dark Shadows')]

from 2018-2019.

beccadelbens avatar beccadelbens commented on June 3, 2024 1
from networkx import MultiDiGraph

second_graph = MultiDiGraph

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

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

print(second_graph.nodes())
print(second_graph.edges())

from 2018-2019.

dafnikitsiki avatar dafnikitsiki commented on June 3, 2024 1

from networkx import MultiDiGraph

#create a new graph
cast_graph = MultiDiGraph()

#create nodes for movies
cast_graph.add_node("Ocean's Twelve")
cast_graph.add_node("Fight Club")
cast_graph.add_node("Dark Shadows")

#create nodes for actors
cast_graph.add_node("Brad Pitt")
cast_graph.add_node("Eva Green")
cast_graph.add_node("George Clooney")
cast_graph.add_node("Catherine Zeta-Jones")
cast_graph.add_node("Johnny Depp")
cast_graph.add_node("Helena Bonham Carter")

#create edges between actors and movies
cast_graph.add_edge("Brad Pitt", "Ocean's Twelve")
cast_graph.add_edge("Brad Pitt", "Fight Club")
cast_graph.add_edge("Eva Green", "Dark Shadows")
cast_graph.add_edge("George Clooney", "Ocean's Twelve")
cast_graph.add_edge("Catherine Zeta-Jones", "Ocean's Twelve")
cast_graph.add_edge("Johnny Depp", "Dark Shadows")
cast_graph.add_edge("Helena Bonham Carter", "Fight Club")
cast_graph.add_edge("Helena Bonham Carter", "Dark Shadows")

print(cast_graph.nodes())
print(cast_graph.edges())

from 2018-2019.

MilenaCorbellini avatar MilenaCorbellini commented on June 3, 2024
from networkx import MultiDiGraph
movies_graph= MultiDiGraph()
#Actors
movies_graph.add_node("Brad Pit")
movies_graph.add_node("Eva Green")
movies_graph.add_node("George Clooney")
movies_graph.add_node("Chaterine Zeta-Jones")
movies_graph.add_node("Jonny Deep")
movies_graph.add_node("Helena Bonham Carter")
#Movies
movies_graph.add_node("Ocean's Twelve")
movies_graph.add_node("Fight Club")
movies_graph.add_node("Dark Shadows")

movies_graph.add_edge("Brad Pit", "Ocean's Twelve", color = 'r')
movies_graph.add_edge("George Clooney", "Ocean's Twelve", color = 'r')
movies_graph.add_edge("Chaterine Zeta-Jones", "Ocean's Twelve", color = 'r')

movies_graph.add_edge("Brad Pit", "Fight Club", color = 'blue')
movies_graph.add_edge("Helena Bonham Carter", "Fight Club", color= 'blue')

from 2018-2019.

mangiafrangette avatar mangiafrangette commented on June 3, 2024
from networkx import MultiDiGraph

actor_movie_graph = MultiDiGraph()

# adding actors
actor_movie_graph.add_node("Brad Pitt")
actor_movie_graph.add_node("Eva Green")
actor_movie_graph.add_node("George Clooney")
actor_movie_graph.add_node("Catherine Zeta-Jones")
actor_movie_graph.add_node("Johnny Depp")
actor_movie_graph.add_node("Helena Bonham Carter ")

# adding movies
actor_movie_graph.add_node("Ocean's Twelve")
actor_movie_graph.add_node("Fight Club")
actor_movie_graph.add_node("Dark Shadows")

# adding edges
actor_movie_graph.add_edge("George Clooney", "Ocean's Twelve")
actor_movie_graph.add_edge("Brad Pitt", "Ocean's Twelve")
actor_movie_graph.add_edge("Catherine Zeta-Jones", "Ocean's Twelve")
actor_movie_graph.add_edge("Brad Pitt", "Fight Club")
actor_movie_graph.add_edge("Helena Bonham Carter", "Fight Club")
actor_movie_graph.add_edge("Brad Pitt", "Dark Shadows")
actor_movie_graph.add_edge("Helena Bonham Carter", "Dark Shadows")
actor_movie_graph.add_edge("Eva Green", "Dark Shadows")

from 2018-2019.

bluebell94 avatar bluebell94 commented on June 3, 2024

from networkx import MultiDiGraph
movie_stars = MultiDiGraph()
movie_stars.add_node("a",weight="Ocean's Twelve")
movie_stars.add_node("b",weight="Fight Club")
movie_stars.add_node("c",weight="Dark Shadows")
movie_stars.add_node(1, weight="Brad Pitt")
movie_stars.add_node(2, weight="George Clooney")
movie_stars.add_node(3, weight="Eva Green")
movie_stars.add_node(4, weight="Catherine Zeta-Jones")
movie_stars.add_node(6, weight="Helena Bonham Carter")

movie_stars.add_edge(1,"a")
movie_stars.add_edge(1,"b")
movie_stars.add_edge(2,"a")
movie_stars.add_edge(3,"c")
movie_stars.add_edge(4,"a")
movie_stars.add_edge(5,"c")
movie_stars.add_edge(6,"b")
movie_stars.add_edge(6,"c")

print(movie_stars.nodes(data=True))
print(movie_stars.edges(data=True))

[('a', {'weight': "Ocean's Twelve"}), ('b', {'weight': 'Fight Club'}), ('c', {'weight': 'Dark Shadows'}), (1, {'weight': 'Brad Pitt'}), (2, {'weight': 'George Clooney'}), (3, {'weight': 'Eva Green'}), (4, {'weight': 'Catherine Zeta-Jones'}), (6, {'weight': 'Helena Bonham Carter'}), (5, {})]
[(1, 'a', {}), (1, 'b', {}), (2, 'a', {}), (3, 'c', {}), (4, 'a', {}), (6, 'b', {}), (6, 'c', {}), (5, 'c', {})]

from 2018-2019.

essepuntato avatar essepuntato commented on June 3, 2024

Hi @andreamust

is there a way to print only the attributes without the node identifiers?

Not to my knowledge – of course, you can implement a function that does exactly that, if you want.

Another comment for @bluebell94: use appropriate attribute names for specifying values – e.g. I do not expect to have a name associated to the attribute weight, bur rather a number. If you want to specify the names as attributes, please look at the way @andreamust did.

from 2018-2019.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.