如何在 gnuplot 中存储和访问矩阵元素?
How can I store and access matrix elements in gnuplot?
我正在尝试制作 19x19 的六边形格子,每个格子都包含一个圆柱体,其颜色不同,描述为 'hexagon.dat'。
2-> 红色圆柱体
1-> 圆柱体颜色为绿色
hexagon.dat
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
但是目前,由于我不知道如何存储和访问hexagon.dat的矩阵数据,所以只有绿色圆柱体
这是我的 gnuplot
脚本
脚本
set term X11 persist title "test" size 1000, 1000
P = 0.78
pin_id = 0
do for [pin_ix=-9:9]{
do for [pin_iy=-9:9]{
cx = pin_ix*P + pin_iy*(-P/2)
cy = pin_iy*sqrt(3)/2*P
pin_id = pin_id + 1
set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
to cx, cy+P/sqrt(3) \
to cx+P/2, cy+P/2/sqrt(3) \
to cx+P/2, cy-P/2/sqrt(3) \
to cx, cy-P/sqrt(3) \
to cx-P/2, cy-P/2/sqrt(3) \
to cx-P/2, cy+P/2/sqrt(3) \
fs solid fc rgb "red"
pin_id = pin_id + 1
set object pin_id circle at cx, cy size 0.3275 \
fs solid fc rgb "green"
}
}
set size ratio 1.0
set xr [-11:11]
set yr [-11:11]
plot 1/0
我在等你的帮助。
您可以使用 plot ... with circles
绘制圆柱体。然后你可以 select 颜色 lc variable
:
P = 0.78
pin_id = 0
do for [pin_ix=-9:9]{
do for [pin_iy=-9:9]{
cx = pin_ix*P + pin_iy*(-P/2)
cy = pin_iy*sqrt(3)/2*P
pin_id = pin_id + 1
set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
to cx, cy+P/sqrt(3) \
to cx+P/2, cy+P/2/sqrt(3) \
to cx+P/2, cy-P/2/sqrt(3) \
to cx, cy-P/sqrt(3) \
to cx-P/2, cy-P/2/sqrt(3) \
to cx-P/2, cy+P/2/sqrt(3) \
fs solid fc rgb "red"
pin_id = pin_id + 1
}
}
set size ratio 1.0
set xr [-11:11]
set yr [-11:11]
set style fill solid noborder
set linetype 1 lc rgb 'red'
set linetype 2 lc rgb 'green'
plot 'hexagon.dat' matrix using ((-9)*P + (-9)*(-P/2)):((-9)*sqrt(3)/2 * P):(0.3275):3 with circles lc variable
在 5.0 版中,您可以使用 stats
来提取矩阵维度:
stats 'hexagon.dat' matrix
N = int(STATS_size_x)
do for [pin_ix=-(N/2):((N-1)/2)] {
...
新十六进制数据
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
脚本
set term X11 persist title "test" size 1000, 1000
P = 0.78
pin_id = 0
do for [pin_ix=-9:9]{
do for [pin_iy=-9:9]{
cx = pin_ix*P + pin_iy*(-P/2)
cy = pin_iy*sqrt(3)/2*P
pin_id = pin_id + 1
set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
to cx, cy+P/sqrt(3) \
to cx+P/2, cy+P/2/sqrt(3) \
to cx+P/2, cy-P/2/sqrt(3) \
to cx, cy-P/sqrt(3) \
to cx-P/2, cy-P/2/sqrt(3) \
to cx-P/2, cy+P/2/sqrt(3) \
fs solid fc rgb "red"
pin_id = pin_id + 1
}
}
set size ratio 1.0
set xr [-11:11]
set yr [-11:11]
set style fill solid noborder
set linetype 1 lc rgb 'green'
set linetype 2 lc rgb 'red'
plot 'NewHexData' matrix using ((-9)*P + (-9)*(-P/2)):((-9)*sqrt(3)/2 * P):(0.3275):3 with circles lc variable
由于我没有足够的声誉,我无法上传生成的图像。
无论如何我得到了这个数字。
真的很感谢Christoph!
我正在尝试制作 19x19 的六边形格子,每个格子都包含一个圆柱体,其颜色不同,描述为 'hexagon.dat'。
2-> 红色圆柱体
1-> 圆柱体颜色为绿色
hexagon.dat
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
但是目前,由于我不知道如何存储和访问hexagon.dat的矩阵数据,所以只有绿色圆柱体 这是我的 gnuplot
脚本脚本
set term X11 persist title "test" size 1000, 1000
P = 0.78
pin_id = 0
do for [pin_ix=-9:9]{
do for [pin_iy=-9:9]{
cx = pin_ix*P + pin_iy*(-P/2)
cy = pin_iy*sqrt(3)/2*P
pin_id = pin_id + 1
set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
to cx, cy+P/sqrt(3) \
to cx+P/2, cy+P/2/sqrt(3) \
to cx+P/2, cy-P/2/sqrt(3) \
to cx, cy-P/sqrt(3) \
to cx-P/2, cy-P/2/sqrt(3) \
to cx-P/2, cy+P/2/sqrt(3) \
fs solid fc rgb "red"
pin_id = pin_id + 1
set object pin_id circle at cx, cy size 0.3275 \
fs solid fc rgb "green"
}
}
set size ratio 1.0
set xr [-11:11]
set yr [-11:11]
plot 1/0
我在等你的帮助。
您可以使用 plot ... with circles
绘制圆柱体。然后你可以 select 颜色 lc variable
:
P = 0.78
pin_id = 0
do for [pin_ix=-9:9]{
do for [pin_iy=-9:9]{
cx = pin_ix*P + pin_iy*(-P/2)
cy = pin_iy*sqrt(3)/2*P
pin_id = pin_id + 1
set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
to cx, cy+P/sqrt(3) \
to cx+P/2, cy+P/2/sqrt(3) \
to cx+P/2, cy-P/2/sqrt(3) \
to cx, cy-P/sqrt(3) \
to cx-P/2, cy-P/2/sqrt(3) \
to cx-P/2, cy+P/2/sqrt(3) \
fs solid fc rgb "red"
pin_id = pin_id + 1
}
}
set size ratio 1.0
set xr [-11:11]
set yr [-11:11]
set style fill solid noborder
set linetype 1 lc rgb 'red'
set linetype 2 lc rgb 'green'
plot 'hexagon.dat' matrix using ((-9)*P + (-9)*(-P/2)):((-9)*sqrt(3)/2 * P):(0.3275):3 with circles lc variable
在 5.0 版中,您可以使用 stats
来提取矩阵维度:
stats 'hexagon.dat' matrix
N = int(STATS_size_x)
do for [pin_ix=-(N/2):((N-1)/2)] {
...
新十六进制数据
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
脚本
set term X11 persist title "test" size 1000, 1000
P = 0.78
pin_id = 0
do for [pin_ix=-9:9]{
do for [pin_iy=-9:9]{
cx = pin_ix*P + pin_iy*(-P/2)
cy = pin_iy*sqrt(3)/2*P
pin_id = pin_id + 1
set object pin_id poly from cx-P/2, cy+P/2/sqrt(3) \
to cx, cy+P/sqrt(3) \
to cx+P/2, cy+P/2/sqrt(3) \
to cx+P/2, cy-P/2/sqrt(3) \
to cx, cy-P/sqrt(3) \
to cx-P/2, cy-P/2/sqrt(3) \
to cx-P/2, cy+P/2/sqrt(3) \
fs solid fc rgb "red"
pin_id = pin_id + 1
}
}
set size ratio 1.0
set xr [-11:11]
set yr [-11:11]
set style fill solid noborder
set linetype 1 lc rgb 'green'
set linetype 2 lc rgb 'red'
plot 'NewHexData' matrix using ((-9)*P + (-9)*(-P/2)):((-9)*sqrt(3)/2 * P):(0.3275):3 with circles lc variable
由于我没有足够的声誉,我无法上传生成的图像。 无论如何我得到了这个数字。
真的很感谢Christoph!