1. 特色网络图
修改节点与边颜色、大小等
import networkx as nx
import matplotlib.pyplot as plt
plt.figure('设备-用户关系图', figsize=(4, 6)) # 设置画布大小
list_fid = [1, 2, 3, 4] # 添加设备节点
list_uid = ["a", "b", "c"] # 添加用户节点
edges = [(1, "a"), (1, "b"), (2, "b"), (2, "c"), (3, "c"), (4, "a")] # 添加关系
# --------- 在图中添加节点与边 ---------
B = nx.Graph()
# B.add_nodes_from(list_fid, bipartite=0)
# B.add_nodes_from(list_uid, bipartite=1)
B.add_nodes_from(list_fid)
B.add_nodes_from(list_uid)
# B.add_nodes_from(list_cid) # 不止二部图,可以多个网络图
B.add_edges_from(edges)
# --------- 设定坐标 画节点 ---------
pos_fid = dict((n, (1, i*1.18)) for i, n in enumerate(list_fid)) # 可通过乘系数,调整节点分布
pos_uid = dict((n, (2, i*1.58)) for i, n in enumerate(list_uid))
nx.draw_networkx_nodes(G=B, pos=pos_fid, nodelist=list_fid, node_size=300, node_color='red', margins=0.001)
nx.draw_networkx_nodes(G=B, pos=pos_uid, nodelist=list_uid, node_size=300, node_color='blue', margins=0.001)
# --------- 设定坐标 画节边 --

最低0.47元/天 解锁文章
2565

被折叠的 条评论
为什么被折叠?



