使用 networkx 绘制图
In [1]:
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
In [2]:
SIZE = 10
T = nx.DiGraph()
A = np.zeros((SIZE, SIZE))
for i in range(SIZE):
for j in range(i):
if i == j:
pass
else:
if (np.random.binomial(n=1, p=0.5, size=1) == 1)[0]:
A[i, j] = 1
else:
A[j, i] = 1
for i in range(SIZE):
for j in range(SIZE):
if A[i][j] == 1:
T.add_edge(i, j)
nx.draw(T)
plt.show()
评论