text_html_output_1.png
import networkx as nx

import plotly.graph_objects as go

import sys
import plotly.graph_objects as go
import networkx as nx
node_list = list(['Chloroquine phosphate', 'Spike (S) antibody', 'IL-6 antibody', 'Remdesivir', 'Favipiravir', 'Fluorouracil', 'Ribavirin', 'Acyclovir', 'Ritonavir', 'Lopinavir', 'Kaletra', 'Darunavir', 'Arbidol', 'Hydroxychloroquine', 'Oseltamivir'])
G = nx.Graph()
for i in node_list:
    G.add_node(i)
G.add_edges_from([('Spike (S) antibody', 'IL-6 antibody')])
G.add_edges_from([('Remdesivir', 'Favipiravir')])
G.add_edges_from([('Remdesivir', 'Fluorouracil')])
G.add_edges_from([('Remdesivir', 'Ribavirin')])
G.add_edges_from([('Remdesivir', 'Acyclovir')])
G.add_edges_from([('Fluorouracil', 'Favipiravir')])
G.add_edges_from([('Ribavirin', 'Favipiravir')])
G.add_edges_from([('Acyclovir', 'Favipiravir')])
G.add_edges_from([('Fluorouracil', 'Ribavirin')])
G.add_edges_from([('Fluorouracil', 'Acyclovir')])
G.add_edges_from([('Ribavirin', 'Acyclovir')])
G.add_edges_from([('Ritonavir', 'Lopinavir')])
G.add_edges_from([('Ritonavir', 'Kaletra')])
G.add_edges_from([('Ritonavir', 'Darunavir')])
G.add_edges_from([('Lopinavir', 'Kaletra')])
G.add_edges_from([('Lopinavir', 'Darunavir')])
G.add_edges_from([('Kaletra', 'Darunavir')])
G.add_edges_from([('Arbidol', 'Hydroxychloroquine')])
G.add_edges_from([('Chloroquine phosphate', 'Hydroxychloroquine')])
G.add_edges_from([('Chloroquine phosphate', 'Arbidol')])
pos = nx.spring_layout(G, k=0.5, iterations=50)
for n, p in pos.items():
    G.nodes[n]['pos'] = p
edge_trace = go.Scatter(x=[], y=[], line=dict(width=1, color='#888'), hoverinfo='none', mode='lines')
for edge in G.edges():
    x0, y0 = G.nodes[edge[0]]['pos']
    x1, y1 = G.nodes[edge[1]]['pos']
    edge_trace['x'] += tuple([x0, x1, None])
    edge_trace['y'] += tuple([y0, y1, None])
node_trace = go.Scatter(x=[], y=[], text=[], mode='markers', hoverinfo='text', marker=dict(showscale=True, colorscale='RdBu', reversescale=True, color=[], size=15, colorbar=dict(thickness=5, xanchor='left', titleside='right'), line=dict(width=0)))
for node in G.nodes():
    x, y = G.nodes[node]['pos']
    node_trace['x'] += tuple([x])
    node_trace['y'] += tuple([y])
for node, adjacencies in enumerate(G.adjacency()):
    node_trace['marker']['color'] += tuple([len(adjacencies[1])])
    node_info = adjacencies[0]
    node_trace['text'] += tuple([node_info])
fig = go.Figure(data=[edge_trace, node_trace], layout=go.Layout(title='Groups of drugs in clinical trials by working mechanisms', titlefont=dict(size=12), showlegend=False, hovermode='closest', margin=dict(b=100, l=100, r=100, t=100), annotations=[dict(text='', showarrow=False, xref='paper', yref='paper')], xaxis=dict(showgrid=False, zeroline=False, showticklabels=False), yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))
fig.show()