第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在networkx可視化中為不同的節(jié)點(diǎn)集設(shè)置不同的標(biāo)簽選項(xiàng)?

如何在networkx可視化中為不同的節(jié)點(diǎn)集設(shè)置不同的標(biāo)簽選項(xiàng)?

繁華開滿天機(jī) 2022-10-11 21:06:50
我有一個(gè)由三組節(jié)點(diǎn)組成的圖表 1. 服務(wù)器 2. 站 3. 用戶 我想用網(wǎng)絡(luò)內(nèi)置可視化來繪制它們。在圖中,我想要用戶和站的標(biāo)簽,而不是服務(wù)器的標(biāo)簽。但是,這不起作用。當(dāng)我嘗試這個(gè)時(shí):nx.draw_networkx_nodes(network,                    with_labels=False,                    nodelist=self.servers_idx,                    node_size=50, node_shape='s',                    pos=servers_pos,                    node_color='r')nx.draw_networkx_nodes(network, with_labels=True,                    nodelist=self.stations_idx,                    node_size=50, node_shape='^',                    pos=stations_pos,                    node_color='g')nx.draw_networkx_nodes(network, with_labels=True,                    nodelist=self.users_idx,                    node_size=10, node_shape='o',                    pos=users_pos,                    node_color='b')我得到下圖:如您所見,它沒有顯示任何標(biāo)簽,但我已將with_labels變量值設(shè)置True為站點(diǎn)和用戶,并且期望它會(huì)顯示它們。奇怪的是,當(dāng)我將所有設(shè)置為時(shí)with_labels,True它會(huì)顯示所有標(biāo)簽。但是,如果我只將其中一個(gè)設(shè)置為False它不會(huì)顯示其他兩個(gè)(就像我將它們都設(shè)置為 False 一樣)。有誰知道這里發(fā)生了什么?
查看完整描述

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é)果如下:

http://img1.sycdn.imooc.com//63456a900001cff403890253.jpg

查看完整回答
反對(duì) 回復(fù) 2022-10-11
  • 1 回答
  • 0 關(guān)注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)