簡體   English   中英

散景繪制的 networkx 使用 from_pandas_edgelist 的數據顯示錯誤的結構

[英]networkx plotted by bokeh with data from_pandas_edgelist shows wrong structure

我有一個 dataframe ,其中包含引用它們的文章和文章的名稱:

dic = {'article': ['Needling: is there a point?', 'Needling: is there a point? ',
                'A Delphi Study: Defining a Unicorn.',
                'A Delphi Study: Defining a Unicorn.',
                'A Delphi Study: Defining a Unicorn.'],
       'cited_by': ['The Effects of Dry Needling As a Novel Recovery Strategy on Quadriceps Muscle Fatigue: A Pilot Study ',
               'Dry needling for spine related disorders: a scoping review ',
               'Why are assumptions passed off as established knowledge? ',
               'Needling: is there a point? ',
               'How have the views on myofascial pain and its treatment evolved in the past 20 years? From spray and stretch and injections to pain science, dry needling and fascial treatments. ']}
df = pd.Dataframe()

如果我以這種方式創建網絡,一切都很好:

G = nx.from_pandas_edgelist(df, source='article', target='cited_by', edge_attr=True, create_using=nx.MultiGraph())
nx.draw(G, with_labels=True)

網絡

但是當我嘗試用散景來做時,節點被弄亂了(同名顯示了幾次):

G = nx.from_pandas_edgelist(df, source='article', target='cited_by', edge_attr=True, create_using=nx.MultiGraph())
plot = Plot(plot_width=400, plot_height=400,x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1))
node_hover_tool = HoverTool(tooltips=[("title", "@article")])
plot.add_tools(node_hover_tool) 
graph_renderer = from_networkx(G, nx.circular_layout, scale=1, center=(0, 0))
graph_renderer.node_renderer.glyph = Circle(size=15, fill_color=Spectral4[0])
graph_renderer.edge_renderer.glyph = MultiLine(line_alpha=0.8, line_width=1)
graph_renderer.node_renderer.data_source.data['article'] = df['article']
plot.renderers.append(graph_renderer)
output_file("interactive_graphs.html")
show(plot)

散景網絡

為什么??

節點名稱錯誤。 他們已經在 G 中,所以這是正確的:

graph_renderer.node_renderer.data_source.data['from'] = list(G.nodes)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM