我正在使用 python pyvis 包進(jìn)行節(jié)點(diǎn)可視化。pyvis樹只能在單獨(dú)的html上呈現(xiàn)嗎?我們不能使用 matplotlib 包繪圖嗎?from pyvis.network import Networkimport pandas as pdgot_net = Network(height="750px", width="100%", bgcolor="#222222", font_color="white")# set the physics layout of the networkgot_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 datafor 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") 在上面的代碼中,節(jié)點(diǎn)在新瀏覽器選項(xiàng)卡上以單獨(dú)的 html 呈現(xiàn),我想繪制它們而不是 HTML 之類的plt.plot(got_net)如果有人能幫助理解這個包,我將不勝感激。
2 回答

慕的地10843
TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個贊
notebook = True在構(gòu)造函數(shù)中設(shè)置Network然后添加如下解決了我的實(shí)現(xiàn)的問題:
from IPython.core.display import display, HTML
...
got_net.show("gameofthrones.html")
display(HTML("gameofthrones.html"))
添加回答
舉報(bào)
0/150
提交
取消