0

I have a dataset. I'm building a multigraph based on it. But I can't change the line thickness.

dict_value={'Источник':[10301.0,10301.0,10301.0,10301.0,10329.0,10332.0,10333.0,10334.0,174143.0,1030408.0,10306066.0],
        'Собеседник':[300.0,315.0,343.0,344.0,300.0,300.0,300.0,300.0,300.0,300.0,300.0],
        'Частота':[164975000,164975000,164437500,164975000,164975000,164975000,164975000,164975000,164975000,164975000,164975000],
        'БС LAC':[9,9,1,9,9,9,9,9,9,9,9],
        'Длительность':[20,3,2,2,3,3,2,3,3,3,3]}
session_graph=pd.DataFrame(dict_value)

session_graph

My code:

plt.figure(figsize=(20,20))
G = nx.MultiDiGraph()
for row in session_graph.itertuples():
    if row[4]==1:
       G.add_edge(row[1], row[2],label=row[3],color="green",width=6)
    if row[4]==3:
       G.add_edge(row[1], row[2],label=row[3],color="red",width=0.4)
    if row[4]==4:
       G.add_edge(row[1], row[2],label=row[3],color="blue",width=0.4)
p=nx.drawing.nx_pydot.to_pydot(G)
p.write_png('multi.png')
Image(filename='multi.png')

Otuput:

enter image description here

At the output, you can see that all the thicknesses are the same, but I need them to be different. Don't know how can I change width of line.

Egor_1811
  • 31
  • 5
  • Seems to be a duplicate of [your another question](https://stackoverflow.com/questions/64286893). Consider removing one of the questions. – ilia Oct 12 '20 at 19:41

1 Answers1

0

If you want to change edge thickness, add penwidth to your arguments

G = nx.MultiDiGraph() 
for row in session_graph.itertuples():
    if row[4]==1:
       G.add_edge(row[1], row[2],label=row[3],color="green",width=6, penwidth=6)
    if row[4]==3:
       G.add_edge(row[1], row[2],label=row[3],color="red",width=0.4, penwidth=1)
    if row[4]==4:
       G.add_edge(row[1], row[2],label=row[3],color="blue",width=0.4, penwidth=1)

If you draw your graph in dot format with you will see, that the problem is in GraphViz - it ignores weight argument but works with penwidth parameter, so you need to pass it to the drawing library.
See Graphviz, changing the size of edge question for details.

ilia
  • 620
  • 4
  • 9