散点图进行细胞定位所需的元素如下:
elements=[
{
'data': {'id': 'one', 'label': 'Modified Color'},
'position': {'x': 75, 'y': 75},
},
{
'data': {'id': 'two', 'label': 'Modified Shape'},
'position': {'x': 75, 'y': 200},
},
{
'data': {'id': 'three', 'label': 'Both Modified'},
'position': {'x': 200, 'y': 75},
},
{
'data': {'id': 'four', 'label': 'Regular'},
'position': {'x': 200, 'y': 200}
},
{'data': {'source': 'one', 'target': 'two'}},
{'data': {'source': 'two', 'target': 'three'}},
{'data': {'source': 'three', 'target': 'four'}},
{'data': {'source': 'two', 'target': 'four'}},
]
当然,第一部分包括4个节点,其ID,标签和坐标,而第二部分包括4个边缘,其源和目标。
我有两个数据框,一个用于节点:
ID LABEL X Y
one Modified Color 75 75
two Modified Shape 75 200
three Both Modified 200 75
four Regular 200 200
和一个用于边缘的数据框
SOURCE TARGET
one two
two three
three four
two four
我通常用一个简单的
df.to_dict('records')
在这种情况下,这是行不通的,因为我必须区分节点中字典的“数据”和“位置”块,而仅区分边缘中的数据。
简而言之,我会得到这个:
{
'id': 'one', 'label': 'Modified Color', 'x': 75, 'y': 75
},
代替此:
{
'data': {'id': 'one', 'label': 'Modified Color'},
'position': {'x': 75, 'y': 75},
},
关于如何进行的任何建议?
谢谢