0

Can't set weight for edges in graph. My dataset

enter image description here

    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)

My code:

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",weight=0.9)
    if row[4]==9:
       G.add_edge(row[1], row[2],label=row[3],color="red",weight=0.4)
p=nx.drawing.nx_pydot.to_pydot(G)
p.write_png('multi.png')
Image(filename='multi.png')

enter image description here

Weight don't change! What I do wrong?Con you help me?

Egor_1811
  • 31
  • 5

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",weight=0.9, penwidth = 5)
    if row[4]==9:
       G.add_edge(row[1], row[2],label=row[3],color="red",weight=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.

resulting graph

ilia
  • 620
  • 4
  • 9
  • thank you. The problem is that when the graph is output, the connection lines are all of the same thickness, as I understand the weight value changes its thickness. – Egor_1811 Oct 11 '20 at 11:19
  • Replied to your comment at the answer. Please write that you want to change edge thickness to the question body. – ilia Oct 12 '20 at 19:35