如何在 gnuplot 中为数据文件中的每一行分配特定的标题
How to assign specific title to each line in the data file in gnuplot
我有一个数据文件,它保存了绘制圆的所有 x、y 坐标和半径值。每个圆圈代表一个地区。到目前为止,我画了圆圈。但我想为数据文件中的每一行分配特定的图例。因为在绘制区域之后,我想根据区域编号在该区域上放置一些点。但是我不知道该怎么做。有没有人知道如何根据数据文件中的行号为圆圈分配特定的图例。数据文件看起来像
X Y R Legend
5 6 0.1 1
....
等等。我想使用最后一列作为标题来分配给圆圈。有什么办法吗?
这取决于您希望如何准确显示相应的 "title"。假设数据文件 circles.dat
包含以下数据:
5 6.0 0.1 1
5 5.5 0.1 2
4 5.0 0.2 3
一种选择是绘制圆圈并使用第四列作为标签,这些标签放置在各个圆圈的中心。这可以通过 with labels
绘图样式直接实现:
set terminal pngcairo
set output 'fig1.png'
fName = 'circles.dat'
unset key
set xr [3:6]
set yr [4:7]
set size square
set tics out nomirror
set xtics 3,1,6
set mxtics 2
set ytics 4,1,7
set mytics 2
plot \
fName u 1:2:3 w circles lc rgb 'red' lw 2, \
'' u 1:2:4 w labels tc rgb 'blue'
或者,人们可能想将这些标签放入图表的图例中。也许有一个更优雅的解决方案,但是一种方法是
分别绘制数据文件的每一行并手动提取第四列(用作键标题):
set terminal pngcairo
set output 'fig2.png'
fName = 'circles.dat'
unset key
set xr [3:6]
set yr [4:7]
set size square
set tics out nomirror
set xtics 3,1,6
set mxtics 2
set ytics 4,1,7
set mytics 2
set key top right reverse
stat fName nooutput
plot \
for [i=0:STATS_records-1] fName u 1:2:3 every ::i::i w circles t system(sprintf("awk 'NR==%d{print }' '%s'", i+1, fName))
我有一个数据文件,它保存了绘制圆的所有 x、y 坐标和半径值。每个圆圈代表一个地区。到目前为止,我画了圆圈。但我想为数据文件中的每一行分配特定的图例。因为在绘制区域之后,我想根据区域编号在该区域上放置一些点。但是我不知道该怎么做。有没有人知道如何根据数据文件中的行号为圆圈分配特定的图例。数据文件看起来像
X Y R Legend
5 6 0.1 1
....
等等。我想使用最后一列作为标题来分配给圆圈。有什么办法吗?
这取决于您希望如何准确显示相应的 "title"。假设数据文件 circles.dat
包含以下数据:
5 6.0 0.1 1
5 5.5 0.1 2
4 5.0 0.2 3
一种选择是绘制圆圈并使用第四列作为标签,这些标签放置在各个圆圈的中心。这可以通过 with labels
绘图样式直接实现:
set terminal pngcairo
set output 'fig1.png'
fName = 'circles.dat'
unset key
set xr [3:6]
set yr [4:7]
set size square
set tics out nomirror
set xtics 3,1,6
set mxtics 2
set ytics 4,1,7
set mytics 2
plot \
fName u 1:2:3 w circles lc rgb 'red' lw 2, \
'' u 1:2:4 w labels tc rgb 'blue'
或者,人们可能想将这些标签放入图表的图例中。也许有一个更优雅的解决方案,但是一种方法是 分别绘制数据文件的每一行并手动提取第四列(用作键标题):
set terminal pngcairo
set output 'fig2.png'
fName = 'circles.dat'
unset key
set xr [3:6]
set yr [4:7]
set size square
set tics out nomirror
set xtics 3,1,6
set mxtics 2
set ytics 4,1,7
set mytics 2
set key top right reverse
stat fName nooutput
plot \
for [i=0:STATS_records-1] fName u 1:2:3 every ::i::i w circles t system(sprintf("awk 'NR==%d{print }' '%s'", i+1, fName))