如何用gnuplot绘制网络图

如何用gnuplot绘制网络图,gnuplot,Gnuplot,我有一份超过100点的清单。我想画一个像这幅画一样的人物。这些线连接距离小于3的任意两点 1.53 2.40 5.39 3.02 4.35 1.29 9.58 8.34 6.59 1.45 3.44 3.45 7.22 0.43 0.23 8.09 4.38 3.49 您可能必须检查每个点与其他点之间的距离是否小于阈值。因此,创建一个包含所有这些点的表格,它们之间的向量,并用向量绘制它们。以下示例使用随机大小和随机颜色创建一些随机点 代码: ### Plo

我有一份超过100点的清单。我想画一个像这幅画一样的人物。这些线连接距离小于3的任意两点

1.53   2.40
5.39   3.02
4.35   1.29
9.58   8.34
6.59   1.45
3.44   3.45
7.22   0.43
0.23   8.09
4.38   3.49

您可能必须检查每个点与其他点之间的距离是否小于阈值。因此,创建一个包含所有这些点的表格,它们之间的向量,并用向量绘制它们。以下示例使用随机大小和随机颜色创建一些随机点

代码:

### Plot connections between points which are closer than a threshold
reset session
set size square

# create some random test data
set print $Data
    myColors = "0xe71840 0x4d76c3 0xf04092 0x47c0ad 0xf58b1e 0xe6eb18 0x59268e 0x36b64c"
    myColor(n) = int(word(myColors,n))
    do for [i=1:100] {
        print sprintf("%g %g %g %d", rand(0), rand(0), rand(0)*2+1, myColor(int(rand(0)*8)+1))
    }
set print

d(x1,y1,x2,y2) = sqrt((x2-x1)**2 + (y2-y1)**2)
myDist = 0.2

set print $Connect
    do for [i=1:|$Data|-1] {
        x1=real(word($Data[i],1))
        y1=real(word($Data[i],2))
        do for [j=i+1:|$Data|] {
            x2=real(word($Data[j],1))
            y2=real(word($Data[j],2))
            if (d(x1,y1,x2,y2)<myDist) { print sprintf("%g %g %g %g", x1, y1, x2-x1, y2-y1) }
        }
    }
set print

set key noautotitle
plot $Connect u 1:2:3:4 w vec lc "grey" nohead, \
        $Data u 1:2:3:4 w p pt 7 ps var lc rgb var
### end of code
###绘制接近阈值的点之间的连接
重置会话
定格
#创建一些随机测试数据
设置打印$Data
myColors=“0xe71840 0x4d76c3 0xf04092 0x47c0ad 0xf58b1e 0xe6eb18 0x59268e 0x36b64c”
myColor(n)=int(单词(myColors,n))
为[i=1:100]做的事{
打印sprintf(“%g%g%g%d”、兰特(0)、兰特(0)、兰特(0)*2+1、myColor(整数(兰特(0)*8)+1))
}
套印
d(x1,y1,x2,y2)=sqrt((x2-x1)**2+(y2-y1)**2)
myDist=0.2
设置打印$Connect
[i=1:|$Data |-1]的do{
x1=实数(字($Data[i],1))
y1=实数(字($Data[i],2))
[j=i+1:|$Data |]{
x2=实数(字($Data[j],1))
y2=实数(字($Data[j],2))

如果(d(x1,y1,x2,y2)您没有指定如何选择节点大小或颜色。我展示了一个使用恒定点大小并从连续线型中获取颜色的示例

[![enter image description here][1]][1]$DATA << EOD
1.53   2.40
5.39   3.02
4.35   1.29
9.58   8.34
6.59   1.45
3.44   3.45
7.22   0.43
0.23   8.09
4.38   3.49
EOD

N = |$DATA|

do for [i=1:N] {
    do for [j=i+1:N] {
        x0 = real(word($DATA[i],1))
        y0 = real(word($DATA[i],2))
        x1 = real(word($DATA[j],1))
        y1 = real(word($DATA[j],2))
        if ((x1-x0)**2 + (y1-y0)**2 <= 9) {
            set arrow from x0,y0 to x1,y1 nohead
        }
    }
}
unset border
unset tics
unset key
set pointsize 3

plot $DATA using 1:2:0 with points pt 7 lc variable
[![在此处输入图像描述][1][1]$DATA