I am working on the cover of plot.ly for my network diagrams adapted from https://plot.ly/python/network-graphs/ . I cannot figure out how to change the width for each connection based on the weights. The scales are in attr_dict
like weight
. I tried to set the objects go.Line
, but it did not work :(. Any suggestions? (And links to tutorials, if possible :)). Attaching an example of a network structure from the graph I made in matplotlib.
How to set an individual line width for each connection in graphical mode?

import requests
from ast import literal_eval
import plotly.offline as py
from plotly import graph_objs as go
py.init_notebook_mode(connected=True)
pos = literal_eval(requests.get("https://pastebin.com/raw/P5gv0FXw").text)
df_plot = pd.DataFrame(pos).T
df_plot.columns = list("xy")
edgelist = literal_eval(requests.get("https://pastebin.com/raw/2a8ErW7t").text)
_fig_kws={"figsize":(10,10)}
def plot_networkx_plotly(df_plot, pos, edgelist, _fig_kws):
node_trace = go.Scattergl(
x=df_plot["x"],
y=df_plot["y"],
mode="markers",
)
edge_trace = go.Scattergl(
x=[],
y=[],
line=[],
mode="lines"
)
for node_A, node_B, attr_dict in edgelist:
xA, yA = pos[node_A]
xB, yB = pos[node_B]
edge_trace["x"] += [xA, xB, None]
edge_trace["y"] += [yA, yB, None]
edge_trace["lines"].append(go.Line(width=attr_dict["weight"],color='#888'))
data = [node_trace, edge_trace]
layout = {
"width":_fig_kws["figsize"][0]*100,
"height":_fig_kws["figsize"][1]*100,
}
fig = dict(data=data, layout=layout)
py.iplot(fig)
return fig
plot_networkx_plotly(df_plot, pos, edgelist, _fig_kws)
Update using Jan Kent's answer:
, . 0.1
weights
:

, width=0.1
, :
