首页 > 解决方案 > 如何通过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

https://www.codeproject.com/Articles/1237026/Simple-MLP-Backpropagation-Artificial-Neural-Netwo 在此处输入图像描述

标签: gnuplot

解决方案


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

代码:

### 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

结果:

在此处输入图像描述


推荐阅读