显示图形时我无法更改线宽 [英] I can't change the line thickness when displaying the graph

查看:55
本文介绍了显示图形时我无法更改线宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集.我正在基于它构建多图.但是我不能更改线的粗细.

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

session_graph

我的代码:

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')

赔率:

在输出中,您可以看到所有厚度都相同,但是我需要它们不同.不知道如何更改线宽.

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.

推荐答案

如果要更改边缘厚度,请在参数中添加 penwidth

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)

如果用 dot 格式绘制图形,您将看到问题出在GraphViz中-它忽略了weight参数,但可以使用 penwidth 参数,因此您需要将其传递到图形库.
有关详细信息,请参见 Graphviz,更改边的大小问题.

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.

这篇关于显示图形时我无法更改线宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆