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
https://www.codeproject.com/Articles/1237026/Simple-MLP-Backpropagation-Artificial-Neural-Netwo
解决方案
您可能必须检查每个点与其他点的距离是否小于您的阈值。因此,创建一个包含所有这些点的表格,它们之间的向量并绘制它们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
结果:
推荐阅读
- python - 将多个numpy时间序列数组插入一个数组的最有效和/或最简单的方法?
- python - 通过带有 Ctypes 模块的 Python 获取剪贴板(在 Linux 中)
- sqlite - blob 数据类型可以是 .xml 或 .json 的文件吗?
- javascript - React-big-calendar 与拖放
- python - ('filename','w') 是否替换或添加
- python - Python ImportError:从转换器导入 BertTokenizer、BertConfig
- kubernetes-helm - 如何将托管在 Docker Registry 中的 Helm 图表用作 Spinnaker 管道工件
- ruby - 使用数组作为内部值创建一个 ruby 嵌套哈希
- c# - 我可以转换列表
到 IEnumerable