1 回答

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊
正如 Paul Brodersen 所說,它看起來像一個(gè) networkx 錯(cuò)誤。但是您可以通過nx.draw_networkx_labels
對(duì)用戶和站點(diǎn)使用函數(shù)來繞過它,但對(duì)于服務(wù)器則不行:
import networkx as nx
network = nx.Graph()
network.add_nodes_from([1, 2, 3, 4, 5])
# Manually create positions and indices
servers_pos = {1: (-1, 1), 2: (1, 1)}
stations_pos = {3: (0, -1), 4: (1, 0)}
users_pos = {5: (0, 0)}
servers_idx = [1, 2]
stations_idx = [3, 4]
users_idx = [5]
# Draw nodes (exactly your code, but without `with_labels` attribute)
nx.draw_networkx_nodes(network, nodelist=[1, 2], node_size=50, node_shape='s', pos=servers_pos, node_color='r')
nx.draw_networkx_nodes(network, nodelist=[3, 4], node_size=50, node_shape='^', pos=stations_pos, node_color='g')
nx.draw_networkx_nodes(network, nodelist=[5], node_size=10, node_shape='o', pos=users_pos, node_color='b')
# Manually create labels for users and stations
stations_labels = {3: 'WAKA-3', 4: 'WAKA-4'}
users_labels = {5: 'John Doe'}
nx.draw_networkx_labels(
network,
pos=stations_pos,
labels=stations_labels
)
nx.draw_networkx_labels(
network,
pos=users_pos,
labels=users_labels
)
結(jié)果如下:
添加回答
舉報(bào)