I was playing around with the API and was wondering if there is a way to center the node. In this toy example, I would like to center the node 'Joshua' but every time I reload the page, Joshua is in a different position. I have tried setting the x and y values when adding nodes but did not have success.
Is it possible to center nodes and if so, what am I doing wrong? Thanks.
from pyvis.network import Network
from pyvis import options
import pandas as pd
got_net = Network(height="500px", width="990px", directed=True)
# set the physics layout of the network
got_net.barnes_hut()
# got_data = pd.read_csv("https://www.macalester.edu/~abeverid/data/stormofswords.csv")
# print(got_net.toggle_stabilization(False))
data = [['tom', 'joshua', 1], ['nick' , 'joshua', 1], ['juli', 'tom', 1], ['joshua', 'tom', 1], ['juli', 'isiah', 1], ]
got_data = pd.DataFrame(data, columns = ['Source', 'Target', 'Weight'])
sources = got_data['Source']
targets = got_data['Target']
weights = got_data['Weight']
edge_data = zip(sources, targets, weights)
for e in edge_data:
src = e[0]
dst = e[1]
w = e[2]
# Use the below to set the edges for the color
if src!='joshua':
got_net.add_node(src, src, title=src, mass = 1)
else:
got_net.add_node(src, src, title=src, x = 500, y = 250, mass = 5)
if dst!='joshua':
got_net.add_node(dst, dst, title=dst, mass=1)
else:
got_net.add_node(dst, dst, title=dst, x = 500, y = 250, mass = 5)
got_net.add_edge(src, dst, value=w, arrowStrikethrough = True)
neighbor_map = got_net.get_adj_list()
# add neighbor data to node hover data
for node in got_net.nodes:
node["title"] += " Neighbors:<br>" + "<br>".join(neighbor_map[node["id"]])
node["value"] = len(neighbor_map[node["id"]])
got_net.save_graph("gameofthrones.html")
nodes, edges, height, width, options = got_net.get_network_data()