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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

NetworkX 二分顏色混合順序

NetworkX 二分顏色混合順序

明月笑刀無情 2021-11-09 10:51:25
我使用 NetworkX 創(chuàng)建了一個二部圖,并想分別為這兩組著色。我使用color()networkX 二分模塊中的函數(shù)。但是,color dict 中的節(jié)點順序與 B.nodes 中的節(jié)點順序不同,例如:B.nodes = ['a', 1, 2, 3, 4, 'c', 'b']二分。顏色(B)= {'a': 1, 1: 0, 2: 0, 'b': 1, 4: 0, 'c': 1, 3: 0}這會導致圖表顏色不正確,如下所示:代碼如下:B = nx.Graph()B.add_nodes_from([1,2,3,4], bipartite=0) # Add the node attribute "bipartite"B.add_nodes_from(['a','b','c'], bipartite=1)B.add_edges_from([(1,'a'), (1,'b'), (2,'b'), (2,'c'), (3,'c'), (4,'a')])bottom_nodes, top_nodes = bipartite.sets(B)color = bipartite.color(B)color_list = []for c in color.values():    if c == 0:        color_list.append('b')    else:        color_list.append('r')# Draw bipartite graphpos = dict()color = []pos.update( (n, (1, i)) for i, n in enumerate(bottom_nodes) ) # put nodes from X at x=1pos.update( (n, (2, i)) for i, n in enumerate(top_nodes) ) # put nodes from Y at x=2nx.draw(B, pos=pos, with_labels=True, node_color = color_list)plt.show()有什么我想念的嗎?
查看完整描述

1 回答

?
滄海一幻覺

TA貢獻1824條經(jīng)驗 獲得超5個贊

繪制圖形時,您的 color_list 和節(jié)點列表(B.nodes)的順序不同。


color_list

['r', 'b', 'b', 'r', 'b', 'r', 'r']


B.nodes

NodeView((1, 2, 3, 4, 'a', 'b', 'c'))

我使用字典創(chuàng)建了一個 color_list 使用 B.nodes 順序,并從 B 中的節(jié)點列表映射二分集。


B = nx.Graph()

B.add_nodes_from([1,2,3,4], bipartite=0) # Add the node attribute "bipartite"

B.add_nodes_from(['a','b','c'], bipartite=1)

B.add_edges_from([(1,'a'), (1,'b'), (2,'b'), (2,'c'), (3,'c'), (4,'a')])

bottom_nodes, top_nodes = bipartite.sets(B)


color = bipartite.color(B)


color_dict = {0:'b',1:'r'}


color_list = [color_dict[i[1]] for i in B.nodes.data('bipartite')]


# Draw bipartite graph

pos = dict()

color = []

pos.update( (n, (1, i)) for i, n in enumerate(bottom_nodes) ) # put nodes from X at x=1

pos.update( (n, (2, i)) for i, n in enumerate(top_nodes) ) # put nodes from Y at x=2


nx.draw(B, pos=pos, with_labels=True, node_color = color_list)

plt.show()

輸出:

http://img1.sycdn.imooc.com//6189e2520001048304490319.jpg

查看完整回答
反對 回復 2021-11-09
  • 1 回答
  • 0 關注
  • 236 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號