I am looking for a way to create a network graph with Scatter graph objects, as seen here: Network Graphs | Python | Plotly. I want to create a neural network graph, and so far I am getting this results:
The problem is, I don’t know how to make each edge a different color based on its weight. My code for the edge trace is as follows:
edge_trace = go.Scatter( x=edge_position_list_x, y=edge_position_list_y, marker=dict( showscale=True, colorscale='YlGnBu', reversescale=True, color=edge_colors, line_width = 4 ), hoverinfo='none', mode='lines')
My figure code looks like this:
fig = go.Figure(data=[edge_trace, node_trace], layout=go.Layout( title='<br>Neural network structure visualization with Python', titlefont_size=16, showlegend=False, hovermode='closest', margin=dict(b=20, l=5, r=5, t=40), annotations=[dict( text="Python code: <a href='https://plotly.com/ipython-notebooks/network-graphs/'> https://plotly.com/ipython-notebooks/network-graphs/</a>", showarrow=False, xref="paper", yref="paper", x=0.005, y=-0.002)], xaxis=dict(showgrid=False, zeroline=False, showticklabels=False), yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)) )
The ‘edge_colors’ variable is nothing more but a list of weights of each edge. The ‘edge_position_list’ variables are also lists, with each pair of x or y coordinates being followed by a ‘None’ value. I’ve read [Network Graph] Set each edge with different color - #13 by kapital1 topic, but it doesn’t explain how to do the same thing, but in Graph Objects. Any help is greatly appreciated!