I am using python pyvis package for nodes visualization. Is it pyvis tree can only render on separate html? can't we plot using matplotlib package?
from pyvis.network import Network
import pandas as pd
got_net = Network(height="750px", width="100%", bgcolor="#222222", font_color="white")
# set the physics layout of the network
got_net.barnes_hut()
got_data = pd.read_csv("https://www.macalester.edu/~abeverid/data/stormofswords.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()
# 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.show("gameofthrones.html")
In the above code, nodes are rendering in separate html on new browser tab, I want to plot them instead of HTML something like
plt.plot(got_net)
I appreciate if anyone can help to understand this package.
From the pyviz documentation you can set the optional parameter notebook to True in the Network constructor, and if you're in a jupyter notebook it will display it:
got_net = Network(
height="750px",
width="100%",
bgcolor="#222222",
font_color="white",
notebook=True # here
)
...
got_net.show("gameofthrones.html")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With