0

In PyVis - search Node is described a way of including images in nodes when the nodes are added to network one by one.

I wonder if there is a similar way when using net.add_nodes().

I have a .csv file where I can create a column with links to images which should be shown in several nodes. I thought that I could use a list as for adding for instance the labels in order to also show the images.

Something like:

import pandas as pd
from pyvis import network as net

file_nodes = 'x_y_z.csv'

g = net.Network(notebook=True, width="65%", height="1000px", heading="", cdn_resources="remote")

nodes = list(got_nodes['Group'])
level_lst = list(got_nodes['Level'])
descr_lst = list(got_nodes['Group_title'])
color_lst = ['crimson', 'red', 'magenta', 'deepskyblue', 'aqua', 'skyblue', 'lime']
img_lst = list(got_nodes['Image'])
shp_lst = list(got_nodes['Shape'])

color_map = [color_lst[item] for i, item in enumerate(level_lst)]

g.add_nodes(nodes, 
    label=list(got_nodes['Group']), 
    title=[descr_lst[i] for i in range(0, len(descr_lst))], 
    color=[color_map[i] for i in range(0, len(color_map))], 
    shape=[f'{shp_lst[i]}' for i in range(0, len(shp_lst))], 
    image=[f'./{img_lst[i]}' for i in range(0, len(img_lst))])

However this does not work.

Any solution?

starball
  • 20,030
  • 7
  • 43
  • 238

1 Answers1

0

Well, as I did not got any further hint, I am creating a function in which I create every single node with the attributes I want them to have, with "g.add_node(node, title, label, shape, image)".

I thought a solution where I could use g.add_nodes(node, title, label, shape, image) and assigning to the attributes assignments already saved in a csv file, would be much more elegant and more "pythonic".