Graphviz重叠边缘标签

时间:2017-01-31 23:37:00

标签: python python-2.7 graph graphviz dot

我正在a Python script工作,发现网络中的所有思科设备,我现在正在寻找添加为用户创建图表的选项。

我正在使用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)彼此重叠,很难看出哪个标签适用于哪个边缘。这引出了我的问题,我该如何确保不会发生这种重叠?

解决方案需要是动态的(而不是仅在此图中修复它),以便它也适用于其他网络。

任何建议都将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:3)

您可以尝试在节点中使用边距,使其更大。 边缘的空标签也有助于创造更多空间。

试试这张图:

graph {
    graph [bgcolor="#333333" fontcolor=white fontsize=16 label="Network Map" rankdir=BT]
    node [color="#006699" fillcolor="#006699" fontcolor=white fontname=Helvetica margin=0.4 shape=box style=filled]
    edge [arrowhead=open color=green fontcolor=white fontname=Courier fontsize=14 style=dashed]
        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