我正在研究a Python script,它发现了网络中的所有Cisco设备,现在正在寻找添加为用户创建图表的选项。
我正在使用graphviz Python模块,并且仍在处理代码,但这是它在此时产生的内容:
graph {
graph [nodesep=1.5 ranksep=1]
edge [fontsize=10 weight=0.5]
"R3.lab"
"R3.lab" -- "R1.lab" [headlabel="Fa0/1" taillabel="Fa0/1"]
"R2.lab"
"R2.lab" -- "R1.lab" [headlabel="Fa3/0" taillabel="Fa3/0"]
"R2.lab"
"R2.lab" -- "R1.lab" [headlabel="Fa1/0" taillabel="Fa0/1"]
"R4.lab"
"R4.lab" -- "R1.lab" [headlabel="Fa4/0" taillabel="Fa4/0"]
"R2.lab"
"R2.lab" -- "R3.lab" [headlabel="Fa0/0" taillabel="Fa0/0"]
"R5.lab"
"R5.lab" -- "R3.lab" [headlabel="Fa4/0" taillabel="Fa3/0"]
"R4.lab"
"R4.lab" -- "R3.lab" [headlabel="Fa1/0" taillabel="Fa0/0"]
"R4.lab"
"R4.lab" -- "R2.lab" [headlabel="Fa1/0" taillabel="Fa1/0"]
"R4.lab"
"R4.lab" -- "R5.lab" [headlabel="Fa0/1" taillabel="Fa0/1"]
}
问题在于某些节点的边缘标签(例如R4)彼此重叠,很难看到哪个标签适用于哪个边缘。这就引出了一个问题,我该如何确保不会发生这种重叠?
解决方案将需要是动态的(而不是仅在此图中对其进行修复),以便它也可以在其他网络上使用。
任何建议将不胜感激。谢谢。
最佳答案
您可以尝试在节点中使用边距,以使其更大。
边缘的空标签也有助于创造更多空间。
试试这个图:
图{
图[bgcolor =“#333333” fontcolor = white fontsize = 16 label =“网络地图” rankdir = BT]
节点[color =“#006699” fillcolor =“#006699” fontcolor = white fontname = Helvetica margin = 0.4 shape = box style = filled]
边缘[箭头=开放颜色=绿色fontcolor =白色fontname = Courier fontsize = 14样式=虚线]
R4
R5
R1
R2
R3
R2-R3 [label =“” headlabel =“ Fa0 / 0” taillabel =“ Fa0 / 0”]
R4-R2 [label =“” headlabel =“ Fa1 / 0” taillabel =“ Fa1 / 0”]
R2-R1 [label =“” headlabel =“ Fa3 / 0” taillabel =“ Fa3 / 0”]
R4-R1 [label =“” headlabel =“ Fa4 / 0” taillabel =“ Fa4 / 0”]
R4-R5 [label =“” headlabel =“ Fa0 / 1” taillabel =“ Fa0 / 1”]
R3-R1 [label =“” headlabel =“ Fa0 / 1” taillabel =“ Fa0 / 1”]
R2-R1 [label =“” headlabel =“ Fa0 / 1” taillabel =“ Fa1 / 0”]
R5-R3 [label =“” headlabel =“ Fa3 / 0” taillabel =“ Fa4 / 0”]
}
您可以在要旨中看到完整的代码:https://gist.github.com/natenka/4d991cacc69e7353c84504c1581a5014