From 33dd6730e46af459dd36519c78b522846c926d81 Mon Sep 17 00:00:00 2001 From: Scoodood Date: Mon, 9 Jan 2023 06:23:55 -0800 Subject: [PATCH] Update tutorial.rst 1. Cleaner code. 2. Replace
with "\n" to render the tooltips correctly on my browser. --- pyvis/source/tutorial.rst | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/pyvis/source/tutorial.rst b/pyvis/source/tutorial.rst index 9178baf..6578066 100644 --- a/pyvis/source/tutorial.rst +++ b/pyvis/source/tutorial.rst @@ -168,27 +168,17 @@ The following code block is a minimal example of the capabilities of pyvis. got_net.barnes_hut() got_data = pd.read_csv("../../notebooks/NetworkOfThrones.csv") - 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] - - got_net.add_node(src, src, title=src) - got_net.add_node(dst, dst, title=dst) - got_net.add_edge(src, dst, value=w) - - neighbor_map = got_net.get_adj_list() + for src, dst, w in zip(got_data.Source, got_data.Target, got.Weight): + got_net.add_node(src, src, title=src) + got_net.add_node(dst, dst, title=dst) + got_net.add_edge(src, dst, value=w) # add neighbor data to node hover data + neighbor_map = got_net.get_adj_list() + for node in got_net.nodes: - node["title"] += " Neighbors:
" + "
".join(neighbor_map[node["id"]]) - node["value"] = len(neighbor_map[node["id"]]) + node["title"] += " Neighbors:\n" + "\n".join(neighbor_map[node["id"]]) + node["value"] = len(neighbor_map[node["id"]]) got_net.show("gameofthrones.html")