简体   繁体   中英

networkx plotted by bokeh with data from_pandas_edgelist shows wrong structure

I have a dataframe with names of articles and articles who cited them:

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()

everything is fine if I create a network this way:

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

network

but when i try to do it with bokeh, the nodes are messed up (same names shows a few times):

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)

散景网络

why??

the node names are wrong. they are already in G, so this makes it right:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM