如何在gnuplot上绘制树/图/网络数据?

rgc*_*ini 8 tree plot graph gnuplot nodes

我有一个由边和颜色组成的数据集,我想用类似网络的方式绘制它们,用线条和圆圈(如下图),可能还有簇颜色.

图示例

数据组织如下:

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
Run Code Online (Sandbox Code Playgroud)

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

rgc*_*ini 7

好的,所以我自己弄清楚了,我会在这里留下细节,以帮助任何有同样问题的人.

单节颜色图表,节点上有标签:

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

单色图与节点上的标签

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
Run Code Online (Sandbox Code Playgroud)

几乎没有变化,它可以与问题图片上的那个相匹配.

在此输入图像描述

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
Run Code Online (Sandbox Code Playgroud)

群集色图:

群集色图

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
Run Code Online (Sandbox Code Playgroud)

所有图上使用的数据都遵循以下结构:

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

(...)
Run Code Online (Sandbox Code Playgroud)


hug*_*omg 5

接受的答案对我来说不太有效。这是我必须改变它的方法:

输入文件的格式

# 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

#...
Run Code Online (Sandbox Code Playgroud)

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

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

绘图命令

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
Run Code Online (Sandbox Code Playgroud)

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