I think I need some help...... I'm using Pyvis to visualize a social network graph, and I want to set some options for the network. trying to set some
# Visualization
net = Network(height='1000px',width='80%',bgcolor='#222222',filter_menu=True,select_menu=True, notebook=True,cdn_resources='remote',font_color="white") # define the network class
net.set_options('''
const options = {
"nodes": {
"borderWidth": null,
"borderWidthSelected": null,
"opacity": null,
"size": null
},
"edges": {
"arrows": {
"to": {
"enabled": true
}
},
"color": {
"inherit": true
},
"selfReferenceSize": null,
"selfReference": {
"angle": 0.7853981633974483
},
"smooth": {
"forceDirection": "none"
}
},
"physics": {
"barnesHut": {
"gravitationalConstant": -80000,
"springLength": 250,
"springConstant": 0.001
},
"minVelocity": 0.75
}
}''')
net.barnes_hut()
# Add center nodes
net.add_nodes(selected_nodes[number[0]:number[1]],title = ['1' for i in range(number[0],number[1])],\
color = ['#FFA500' for i in range(number[0],number[1])],\
label = [nodes[selected_nodes[i]] for i in range(number[0],number[1])],size = [degrees[selected_nodes[i]] for i in range(number[0], number[1])])
# Add one hop neighbors
net.add_nodes(selected_nodes[number[1]:number[2]],title = ['2' for i in range(number[1],number[2])],\
color = ['#FFFF00' for i in range(number[1],number[2])],\
label = [nodes[selected_nodes[i]] for i in range(number[1],number[2])],size = [degrees[selected_nodes[i]] for i in range(number[1], number[2])])
net.add_edges(selected_edges[number[1]-number[1]:number[2]-number[1]])
# Add two hop neighbors
net.add_nodes(selected_nodes[number[2]:number[3]],title = ['3' for i in range(number[2],number[3])],\
color = ['#00FFFF' for i in range(number[2],number[3])],\
label = [nodes[selected_nodes[i]] for i in range(number[2],number[3])],size = [degrees[selected_nodes[i]] for i in range(number[2], number[3])])
net.add_edges(selected_edges[number[2]-number[1]:number[3]-number[1]])
# Add complement Edges
net.add_edges(edges_complement)
# Display
net.toggle_physics(True)
net.show_buttons(filter_=['nodes','edges','physics'])
net.show('test.html')
However, when I run the code, I come through an Attribute error.
Traceback (most recent call last): File "D:\Study\Courses\2023Fall\Social Network Mining\FinaL_PJ_code\GCN\pygcn\visualization.py", line 137, in net.barnes_hut() File "D:\Study\Courses\2023Fall\Social Network Mining\FinaL_PJ_code\GCN\venv\lib\site-packages\pyvis\network.py", line 782, in barnes_hut self.options.physics.use_barnes_hut(locals()) AttributeError: 'dict' object has no attribute 'physics'
I think that self.option should be an 'Option' object, rather than a 'dict', but how can I fix it ?
I've tried to look through the source code and figure out how to turn a 'dict' object to an 'Option' object, but failed. That's my first question in Stack Overflow, and I'm looking forward timely helps. Thank you very much.