I'm doing a network visualization using PyVis and was hoping to add some additional items in the tooltip function when hovering on nodes.
I'm basically using the code straight from the tutorial section of the PyVis documentation for the GoT network: https://pyvis.readthedocs.io/en/latest/tutorial.html
The tooltip in this function is set-up so that it will show lists of adjacent neighbors when hovering on a node. I would like to display this same information, but would also like to display the associated edge weight for each neighbor.
I know that weight is being accounted for in my visualization since the edge width is changing depending on the weight, but the few attempts I've made haven't shown any change in the tooltip.
Here is what I've attempted in addition to the code responsible for the tooltip (Tooltip section is toward the bottom, just below the neighbor_map object):
HCP_net = Network(height='750px', width='100%', bgcolor='#222222', font_color='white')
HCP_net.barnes_hut()
sources = df2['HCP_Name']
targets = df2['HCPOffset_Name']
weights = df2['PATIENT_ID (DCOUNT)']
edge_data = zip(sources, targets, weights)
for e in edge_data:
src = e[0]
dst = e[1]
w = e[2]
HCP_net.add_node(src, src, title=src)
HCP_net.add_node(dst, dst, title=dst)
HCP_net.add_edge(src, dst, value=w)
neighbor_map = HCP_net.get_adj_list()
node_weight = HCP_net.get_edges() #my attempt at creating a weight object to call, if I call print(len(node_weight)) I get an integer so I know this is working
for node in HCP_net.nodes:
node['title'] += ' Neighbors: <br>' + '<br>'.join(neighbor_map[node['id']])
node['value'] = len(neighbor_map[node['id']])
node['value'] = len(neighbor_map.keys()) #This called by itself
(print(len(neighbor_map.keys())) also displays the same integer as my node_weight object
I think I'm just not quite understanding how to correctly call the node['value'] to result in a new display in the tool tip. Any assistance is greatly appreciated!