2

I have a list of more than 100 points. I'd like to plot a figure like this picture. The lines connect any two points whose distance is less than 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 enter image description here

Binh Thien
  • 363
  • 2
  • 13

2 Answers2

2

You probably have to check every point against every other point whether the distance is less than your threshold. So, create a table with all these points, the vector between them and plot them with vectors. The following example creates some random points with random sizes and random colors.

Code:

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

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • The principles of these posts about Delaunay triangulation (https://stackoverflow.com/a/68507661), Voronoi diagrams (https://stackoverflow.com/a/73936869) and optimizing node graphs (https://stackoverflow.com/a/74576116) might lead (with some modifications) to similar results. – theozh Mar 22 '23 at 16:23
1

You do not specify how to choose the node size or color. I show an example using a constant pointsize and taking the color from sequential linetypes

[![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

enter image description here

Ethan
  • 13,715
  • 2
  • 12
  • 21