玩具图

此笔记本展示了如何加载一些玩具图。

[1]:
from IPython.display import SVG
[2]:
import numpy as np
[3]:
from sknetwork.data import house, bow_tie, karate_club, miserables, painters, hourglass, star_wars, movie_actor
from sknetwork.visualization import visualize_graph, visualize_bigraph

房屋图

[4]:
graph = house(metadata=True)
adjacency = graph.adjacency
position = graph.position
[5]:
image = visualize_graph(adjacency, position, scale=0.5)
SVG(image)
[5]:
../../_images/tutorials_data_toy_graphs_7_0.svg
[6]:
# adjacency matrix only
adjacency = house()

领带

[7]:
graph = bow_tie(metadata=True)
adjacency = graph.adjacency
position = graph.position
[8]:
image = visualize_graph(adjacency, position, scale=0.5)
[9]:
SVG(image)
[9]:
../../_images/tutorials_data_toy_graphs_12_0.svg

空手道俱乐部

[10]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
labels = graph.labels
[11]:
image = visualize_graph(adjacency, position, labels=labels)
SVG(image)
[11]:
../../_images/tutorials_data_toy_graphs_15_0.svg

悲惨世界

[12]:
graph = miserables(metadata=True)
adjacency = graph.adjacency
position = graph.position
names = graph.names
[13]:
image = visualize_graph(adjacency, position, names, scale=2)
SVG(image)
[13]:
../../_images/tutorials_data_toy_graphs_18_0.svg

画家

[14]:
graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
position = graph.position
[15]:
image = visualize_graph(adjacency, position, names)
SVG(image)
[15]:
../../_images/tutorials_data_toy_graphs_21_0.svg

星球大战

[16]:
# bipartite graph
graph = star_wars(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
[17]:
image = visualize_bigraph(biadjacency, names_row, names_col)
SVG(image)
[17]:
../../_images/tutorials_data_toy_graphs_24_0.svg
[18]:
# biadjacency matrix only
biadjacency = star_wars()

电影-演员

[19]:
# bipartite graph
graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
[20]:
image = visualize_bigraph(biadjacency, names_row, names_col)
SVG(image)
[20]:
../../_images/tutorials_data_toy_graphs_28_0.svg