使用graphvis绘制大图的最佳方法是什么 [英] What is the best way to draw large graph using graphvis

查看:178
本文介绍了使用graphvis绘制大图的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在图像上绘制大型数据集,我使用了graphvis命令行以及所有可用工具(点,neato,twopi等),但结果不可读且包含重叠.

I need to draw large dataset on image, I used graphvis command lines with all available tools (dot, neato, twopi .. etc) but the result is not readable and contains overlapping.

我需要的是在边缘上显示带有标签的节点,并尽量减少重叠,这样图形既可读又可以打印在A4或A3纸上.

What I need is display the nodes with labels on the edges, with minimum overlapping so the graph can be readable and also printed on A4 or A3 paper.

我在neato中使用了选项overlay = false,splines = true和相同的重叠结果.

I used the options overlap=false, splines=true in neato and same overlapping result.

这是数据集:

graph {
    graph [ bgcolor=ivory2, overlap=false, splines=true, ranksep ="2.75"]
    {node [width=1,height=1,shape=circle,style=filled,color=skyblue] "ECNY" }
    edge [ len=2, sep=5] 
    "DANA" -- "HMRN" -- "ECNY" -- "NORI" -- "MAJZ" -- "RSFH" -- "DANA" [label ="LD1-25-A01",  penwidth =3 , color="#156163"]
    "DANA" -- "HMRN" -- "ECNY" -- "NORI" -- "MAJZ" -- "RSFH" -- "DANA" [label ="LD1-25-A02",  penwidth =3 , color="#30a1f9"]
    "DANA" -- "MAJZ" -- "ECNY" -- "HMRN" -- "DANA" [label ="LD1-25-A03",  penwidth =3 , color="#ec591d"]
    "DANA" -- "MAJZ" -- "ECNY" -- "HMRN" -- "DANA" [label ="LD1-25-A04",  penwidth =3 , color="#263a5f"]
    "DANA" -- "ECNY" -- "DANA" [label ="LD3-25-A02",  penwidth =3 , color="#a3517c"]
    "HMRN" -- "ECNY" -- "MAJZ" -- "DANA" -- "HMRN" [label ="LD1-25-H01",  penwidth =3 , color="#800d83"]
    "HMRN" -- "ECNY" -- "MAJZ" -- "DANA" -- "TWRN" -- "HMRN" [label ="LD1-25-H02",  penwidth =3 , color="#89e15a"]
    "HMRN" -- "ECNY" -- "MAJZ" -- "DANA" -- "TWRN" -- "HMRN" [label ="LD3-25-H03",  penwidth =3 , color="#74ed0e"]
    "HMRN" -- "ECNY" -- "HMRN" [label ="JED-10-H08",  penwidth =3 , color="#e8e786"]
    "HMRN" -- "ECNY" -- "MAJZ" -- "DANA" -- "HMRN" [label ="LD1-25-H04",  penwidth =3 , color="#e1f559"]
    "ECNY" -- "HMRN" -- "ECNY" [label ="JED-10-A02",  penwidth =3 , color="#8f7964"]
    "ECNY" -- "HMRN" -- "ECNY" [label ="JED-10-A03",  penwidth =3 , color="#9058f0"]
    "ECNY" -- "HMRN" -- "SBCB" -- "ECNY" [label ="JED-10-A04",  penwidth =3 , color="#b537b7"]
    "ECNY" -- "HMRN" -- "SBCB" -- "ECNY" [label ="JED-10-A05",  penwidth =3 , color="#fc2c2a"]
    "ECNY" -- "HMRN" -- "ECNY" [label ="JED-10-A06",  penwidth =3 , color="#36309c"]
    "ECNY" -- "HMRN" -- "ECNY" [label ="JED-10-A07",  penwidth =3 , color="#25a571"]
    "ECNY" -- "OBHR" -- "ECNY" [label ="JED-10-A26",  penwidth =3 , color="#1a6077"]
    "ECNY" -- "2820" -- "ECNY" [label ="JED-25-A03",  penwidth =3 , color="#8bce8c"]
    "ECNY" -- "2138" -- "2129" -- "ECNY" [label ="JED-25-A04",  penwidth =3 , color="#9b9afa"]
    "ECNY" -- "2017" -- "2013" -- "ECNY" [label ="JED-25-A05",  penwidth =3 , color="#5ea9aa"]
    "ECNY" -- "2027" -- "2128" -- "ECNY" [label ="JED-25-A22",  penwidth =3 , color="#c0c4d4"]
    "ECNY" -- "2130" -- "2137" -- "ECNY" [label ="JED-25-A27",  penwidth =3 , color="#781ce0"]
    "ECNY" -- "DANA" -- "ECNY" [label ="LD3-25-A01",  penwidth =3 , color="#fd5c5a"]
    "ECNY" -- "HMRN" -- "ZJ01" -- "ECNY" [label ="JED-10-H03",  penwidth =3 , color="#32e13b"]
    "ECNY" -- "HMRN" -- "ECNY" [label ="JED-10-H04",  penwidth =3 , color="#487f94"]
    "ECNY" -- "2341" -- "2235" -- "2233" -- "ECNY" [label ="JED-10-H05",  penwidth =3 , color="#82ae2d"]
    "ECNY" -- "HMRN" -- "SBCB" -- "ECNY" [label ="JED-10-H06",  penwidth =3 , color="#f4651c"]
    "ECNY" -- "HMRN" -- "SBCB" -- "ECNY" [label ="JED-10-H07",  penwidth =3 , color="#23dd41"]
    "ECNY" -- "HMRN" -- "OBHR" -- "ECNY" [label ="JED-10-H37",  penwidth =3 , color="#521f43"]
    "ECNY" -- "PROJECT" -- "ECNY" [label ="JED-10-H49",  penwidth =3 , color="#0a4bf1"]
    "ECNY" -- "2234" -- "2246" -- "2245" -- "2320" -- "ECNY" [label ="JED-25-H01",  penwidth =3 , color="#6127e4"]
    "ECNY" -- "2842" -- "2030" -- "ECNY" [label ="JED-25-H03",  penwidth =3 , color="#ce1f98"]
    "ECNY" -- "2170" -- "2166" -- "ECNY" [label ="JED-25-H06",  penwidth =3 , color="#aeb0ce"]
    "ECNY" -- "2158" -- "2144" -- "ECNY" [label ="JED-25-H11",  penwidth =3 , color="#9ef618"]
    "ECNY" -- "5824" -- "2011" -- "ECNY" [label ="JED-25-H15",  penwidth =3 , color="#b2d524"]
    "ECNY" -- "2010" -- "2830" -- "2198" -- "ECNY" [label ="JED-25-H16",  penwidth =3 , color="#53e7ae"]
    "ECNY" -- "2179" -- "ECNY" [label ="JED-25-H17",  penwidth =3 , color="#149169"]
    "ECNY" -- "2211" -- "ECNY" [label ="JED-25-H19",  penwidth =3 , color="#15a51b"]
    "ECNY" -- "2316" -- "ECNY" [label ="JED-25-H20",  penwidth =3 , color="#e91d18"]
    "ECNY" -- "2203" -- "ECNY" [label ="JED-25-H22",  penwidth =3 , color="#38a23a"]
    "ECNY" -- "SBCB" -- "JFCC" -- "ECNY" [label ="JED-25-H33",  penwidth =3 , color="#a1abf4"]
    "ECNY" -- "HMRN" -- "ECNY" [label ="JED-25-H41",  penwidth =3 , color="#c14ff8"]
    "ECNY" -- "TAIF" -- "SNFN" -- "NORI" -- "ECNY" [label ="LD1-10-H04",  penwidth =3 , color="#75fb4f"]
    "ECNY" -- "MAJZ" -- "DANA" -- "TWRN" -- "HMRN" -- "ECNY" [label ="LD1-25-H03",  penwidth =3 , color="#52d1c8"]
    "ECNY" -- "DANA" -- "ECNY" [label ="LD3-25-H01",  penwidth =3 , color="#498a16"]
    "ECNY" -- "DANA" -- "ECNY" [label ="LD3-25-H02",  penwidth =3 , color="#70f831"]
    "ECNY" -- "2310" -- "5880" -- "5301" -- "2248" -- "ECNY" [label ="JED-10-H17",  penwidth =3 , color="#ebb4e1"]
    "SBCB" -- "ECNY" -- "HMRN" -- "JELS" -- "ROMN" -- "OBHR" -- "SAFA" -- "SBCB" [label ="JED-W40-A01",  penwidth =3 , color="#7ff59c"]
    "SBCB" -- "SAFA" -- "OBHR" -- "HMRN" -- "ECNY" -- "SBCB" [label ="JED-10-H35",  penwidth =3 , color="#e817b9"]
    "2171" -- "ECNY" -- "2171" [label ="JED-10-H19",  penwidth =3 , color="#bf1252"]
    "ABHA" -- "ECNY" -- "DANA" -- "ABHA" [label ="LD3-10-H01",  penwidth =3 , color="#8b60ae"]
    "MAJZ" -- "ECNY" -- "DANA" -- "2510" -- "MAJZ" [label ="LD1-10-H02",  penwidth =3 , color="#1e3c55"]
    "2209" -- "2206" -- "ECNY" -- "2209" [label ="JED-25-H02",  penwidth =3 , color="#1b6092"]
    }

这是使用以下选项(在neato中)时的输出之一:

this is one of the output when using these options (in neato):

graph [bgcolor = ivory2,overlay = false,splines = true,ranksep ="2.75"]

graph [ bgcolor=ivory2, overlap=false, splines=true, ranksep ="2.75"]

{节点[width = 1,height = 1,shape = circle,style = filled,color = skyblue] "ECNY"}

{node [width=1,height=1,shape=circle,style=filled,color=skyblue] "ECNY" }

边缘[len = 2,sep = 5]

edge [ len=2, sep=5]

当makelap = scale但仍然无法读取图像时也是如此!

also this when make overlap=scale but still the image is not readable!

overlap = scale,sep = \"+ 25,25 \",splines = true,rankdir = \"TB \"

overlap=scale, sep=\"+25,25\", splines=true, rankdir=\"TB\"

那么还有哪些其他属性可以增强此图呢?

so what other attributes can enhance this graph ?

推荐答案

不可避免地,随着节点和边的数量增加,我们最终将最终没有足够的空间来获得紧凑但清晰的图形.但是,我认为,我们可以做一些事情来改善问题.在这种情况下,我们可以利用以下事实:边的所有序列形成返回"ECNY"的循环.

Inevitably, as the number of nodes and edges increase, we will eventually end up without enough space to have a compact but nevertheless clear graph. However, there are some things we can do to improve matters, I think. In this case, we can take advantage of the fact that all the sequences of edges form loops that return to "ECNY".

首先,我对那些更接近"ECNY"的边缘进行加权(以使它们更具弹性),并默认使它们更长(以使图的中间更加分散),然后对边缘进行加权远离"ECNY".

First, I weighted the edges that are closer to "ECNY" less (so that they are more stretchy) and made them longer by default (so that the middle of the graph was more spread out), and conversely with the edges that are further from "ECNY".

第二,我只给每个循环贴标签一次,标签在边缘处与"ECNY"尽可能远.

Second, I labelled each loop only once, with the label being on the edge as far away from "ECNY" in the loop as I could get it.

我使用Python脚本adjweight.py以编程方式进行了以下更改:

I made these changes programmatically with a Python script adjweight.py as follows:

import sys, re, math

for line in sys.stdin:
    line = line.rstrip()
    if re.match(' +"',line):
        loop, attr = line.split(" [")
        loopli = loop.split(" -- ")[1:] 
        # We take all but the first node, to eliminate repeats
        # then we put the list of edges together with "ECNY" first and last.
        i = loopli.index('"ECNY"')
        loopli = loopli[i:] + loopli[:i] + [loopli[i]]
        n = len(loopli)

        # Now we write the multi-edge lines as individual lines so that we can 
        # give each edge an individual weight and length

        for i in range(n-1):
            # We weight edges that are furthest from the center (i.e. those with 
            # numbers closest to n/2) highest and those that are closest to the
            # center are weighted lowest.
            wt = (n/2)/(abs(n/2 - (i+1))+1)
            edgelength = 1/wt
            if i - n//2 + 1 != 0:
                # This edge is the furthest from the center in this loop, so we 
                # label this edge (but not the other edges in the loop)
                attr = ",".join(attr.split(",")[1:])
            # We raise the weights and edge lengths to different powers to adjust
            # the distribution of nodes across the "diameter" of the graph
            print ("    %s -- %s [weight = %f, len = %f, %s" % (
                loopli[i],loopli[i+1],wt**3,edgelength**2,attr))
    else:
        print (line)

...可以与python adjweight.py <large.dot >large3.dot一起运行,其中large.dot是问题中显示的.dot文件.

... which can be run with python adjweight.py <large.dot >large3.dot, where large.dot is the .dot file shown in the question.

将边缘的fontsize更改为10(与默认值14相比),并通过neato运行large3.dot给出了下图:

Changing the fontsize for the edges to 10 (compared to the default of 14) and running large3.dot through neato gave me the following graph:

这使节点在页面上的分布更加均匀,并且边缘标签也使混乱程度降低了很多,因此对我来说似乎是一种改进.边缘标签仍然与几个节点和(特别是在图形的右上方)其他边缘标签重叠,因为overlap参数仅影响节点和边缘线,而不影响边缘标签.

This has spread the nodes more evenly around the page and it is much less cluttered by edge labels, so it seems like an improvement to me. Edge labels still overlap a few nodes and (particularly in the top right of the graph) other edge labels because the overlap parameter only affects nodes and edge lines, not edge labels.

调整与"ECNY"的距离相关的边缘的相对长度和权重可能会有助于图形的改进.

Tweaking the relative lengths and weights of edges as they relate to the distance from "ECNY" might help improve the graph a bit more.

这篇关于使用graphvis绘制大图的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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