我有源节点和目标节点,我尝试在toyplot中绘制这些节点。有些节点在社区0中,有些节点在社区1中。我想将社区0绘制为绿色,社区1绘制为橙子(如颜色Map表所示),但它们的颜色不正确。当我将节点重新Map为0到9时(source2和target2),生成的图形中所有内容的颜色都正确。
import numpy as np
import pandas as pd
import toyplot
nodes = ['1001', '1002', '1006', '100e', '010c', '0521', '0513', '0710', '0711', '1005']
mapped_nodes = ['0','1','2','3','4','5','6','7','8','9']
event_map = dict(zip(nodes,mapped_nodes))
edges = pd.DataFrame()
edges['source'] = ['010c','0513','0513','0513','0513','0513','0521','0521','0521','0521','0710','0710','0710','1001','1002','1006']
edges['target'] = ['0521','0521','0710','0711','1001','1005','0710','1001','1002','1006','1006','0711','1005','1006','1006','100e']
edges['source2'] = edges['source'].map(event_map)
edges['target2'] = edges['target'].map(event_map)
print('display edges')
display(edges)
# With this, the nodes's community is colored correctly
# i.e., 6, 7, 8 and 9 are clustered together with the correct color value of 1
# edges = np.array(edges[['source2','target2']].values.tolist())
# With this, the nodes's community is colored incorrectly
# i.e., 1005, 0711, 0513 and 0710 should be colored as 1, as found mapped in the "assigned" dataframe
edges = np.array(edges[['source','target']].values.tolist())
print('print edges')
print(edges)
assigned = pd.DataFrame()
assigned['target'] = ['1001','1002','1006','100e','010c','0521','0513','0710','0711','1005']
assigned['target2'] = assigned['target'].map(event_map)
assigned['community'] = [0,0,0,0,0,0,1,1,1,1]
print('display assigned')
display(assigned)
assigned = np.array(assigned[['target','target2','community']].values.tolist())
print('print assigned')
print(assigned)
colormap = toyplot.color.brewer.map("Set2")
display(colormap)
ecolor = "lightgrey"
vlstyle = {"fill":"white"}
vcolor = assigned[:,2].astype(int)
toyplot.graph(edges, ecolor=ecolor, vsize=20, vlstyle=vlstyle, vcolor=(vcolor, colormap))
1条答案
按热度按时间u3r8eeie1#
结果是,你必须对你分配的社区进行分类/排序