【问题标题】:How to plot tree/graph/web data on gnuplot?如何在 gnuplot 上绘制树/图形/网络数据?
【发布时间】:2013-12-22 18:26:12
【问题描述】:

我有一个由边缘和颜色组成的数据集,我想以类似网络的方式绘制它们,使用如下图所示的线条和圆形,并可能使用集群着色。

数据是这样组织的:

point1a_x point1a_y color
point1b_x point1b_y color

point2a_x point2a_y color
point2b_x point2b_y color
(...)

point2n_x point2n_y color
point2n_x point2n_y color

我将如何在 gnuplot 上进行操作?

【问题讨论】:

    标签: graph plot tree gnuplot nodes


    【解决方案1】:

    好的,所以我自己想通了,我会在此处留下详细信息以帮助任何有相同问题的人。

    节点上带有标签的单色图:

    这将生成一个与问题中的图表非常相似的图表,其中包含连接圆圈和标签的线条。

    plot 'edges.dat' u 1:2 with lines lc rgb "black" lw 2 notitle,\
    'edges.dat' u 1:2:(0.6) with circles fill solid lc rgb "black" notitle,\
    'edges.dat' using 1:2:($0) with labels tc rgb "white" offset (0,0) font 'Arial Bold' notitle
    

    只要稍加改动,就可以完全匹配问题图片上的那个。

    plot 'edges.dat' u 1:2 with lines lc rgb "black" lw 2 notitle,\
    'edges.dat' u 1:2:(0.8) with circles linecolor rgb "white" lw 2 fill solid border lc lt 0 notitle, \
    'edges.dat' using 1:2:($0) with labels offset (0,0) font 'Arial Bold' notitle
    

    集群彩色图:

    unset colorbox
    
    set palette model RGB defined ( 0 0 0 0 , 1 1 0 0 , 2 1 0.9 0, 3 0 1 0, 4 0 1 1 , 5 0 0 1 , 6 1 0 1 )
    
    plot 'edges.dat' u 1:2:3 with lines lc palette notitle,\
    'edges.dat' u 1:2:(0.15):3 with circles fill solid palette notitle
    

    所有图上使用的数据都遵循这种结构:

    21.53 9.55 0
    24.26 7.92 0
    
    5.63 3.23 1
    2.65 1.77 1
    
    5.63 3.23 0
    4.27 7.04 0
    
    (...)
    

    【讨论】:

    • 只有一个问题...如果该点有多条线,它会被绘制两次并使用不同的标签...任何解决方法?
    • 我设法找到了解决方法;请参阅我的另一个答案。 tldr 是您在输入文件中指定标签,而不是告诉 gnuplot 计算它们。
    【解决方案2】:

    accepted 的答案对我来说不太合适。这是我必须更改的方法:

    输入文件的格式

    # A vertex has 3 fields: x coordinate, y coordnate and the label
    # An edge consists of two points in consecutive lines
    # There must be one or more blank lines between each edge.
    
    21.53 9.55 A
    24.26 7.92 B
    
    5.63 3.23 C
    2.65 1.77 D
    
    5.63 3.23 C
    4.27 7.04 E
    
    #...
    

    与其他答案相比,最大的区别在于标签属于顶点,而不是边。

    还请注意,我将标签更改为字母而不是数字。标签可以是任何字符串,这样可以更清楚地表明它们不是示例中的顺序索引。

    绘图命令

    plot \
      'edges.dat' using 1:2       with lines lc rgb "black" lw 2 notitle,\
      'edges.dat' using 1:2:(0.6) with circles fill solid lc rgb "black" notitle,\
      'edges.dat' using 1:2:3     with labels tc rgb "white" offset (0,0) font 'Arial Bold' notitle
    

    这里最大的变化是现在在绘制标签时,我们绘制第三个字段而不是 $0 字段,这是一个序列号。

    【讨论】:

    • 虽然用户没有包含节点名称字段,但为了完整起见,这应该是 IMO 接受的答案。顺便问一下,有没有办法把它变成有向图,是否也可以为每条边选择线型?
    猜你喜欢
    • 1970-01-01
    • 2013-03-22
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多