Note
Go to the end to download the full example code.
三元组#
根据Snijders, T. (2012)的论文《传递性和三元组》,牛津大学,存在16种可能的三元组类型。此图展示了在有向网络中可以识别的16种三元组类型。三元组关系在分析社交网络时特别有用。前三位数字表示互惠、非对称和空二元组(双向、单向和非边)的数量,字母表示方向为向上(U)、向下(D)、循环(C)或传递(T)。
import networkx as nx
import matplotlib.pyplot as plt
fig, axes = plt.subplots(4, 4, figsize=(10, 10))
triads = {
"003": [],
"012": [(1, 2)],
"102": [(1, 2), (2, 1)],
"021D": [(3, 1), (3, 2)],
"021U": [(1, 3), (2, 3)],
"021C": [(1, 3), (3, 2)],
"111D": [(1, 2), (2, 1), (3, 1)],
"111U": [(1, 2), (2, 1), (1, 3)],
"030T": [(1, 2), (3, 2), (1, 3)],
"030C": [(1, 3), (3, 2), (2, 1)],
"201": [(1, 2), (2, 1), (3, 1), (1, 3)],
"120D": [(1, 2), (2, 1), (3, 1), (3, 2)],
"120U": [(1, 2), (2, 1), (1, 3), (2, 3)],
"120C": [(1, 2), (2, 1), (1, 3), (3, 2)],
"210": [(1, 2), (2, 1), (1, 3), (3, 2), (2, 3)],
"300": [(1, 2), (2, 1), (2, 3), (3, 2), (1, 3), (3, 1)],
}
for (title, triad), ax in zip(triads.items(), axes.flatten()):
G = nx.DiGraph()
G.add_nodes_from([1, 2, 3])
G.add_edges_from(triad)
nx.draw_networkx(
G,
ax=ax,
with_labels=False,
node_color=["green"],
node_size=200,
arrowsize=20,
width=2,
pos=nx.planar_layout(G),
)
ax.set_xlim(val * 1.2 for val in ax.get_xlim())
ax.set_ylim(val * 1.2 for val in ax.get_ylim())
ax.text(
0,
0,
title,
fontsize=15,
fontweight="extra bold",
horizontalalignment="center",
bbox={"boxstyle": "square,pad=0.3", "fc": "none"},
)
fig.tight_layout()
plt.show()
Total running time of the script: (0 minutes 0.465 seconds)