2017-07-19 14 views
1

我有一个数据文件,它保留绘图圆的所有x,y坐标和半径值。每个圆圈代表一个区域。到现在为止,我画了圈子。但是我想为数据文件中的每一行分配特定的图例。因为在绘制区域之后,我想在这个区域上放一些点数取决于区域编号。但我无法弄清楚如何去做。是否有人知道如何根据数据文件中的行号为圆圈指定特定的图例。数据文件看起来像如何为gnuplot中的数据文件中的每一行分配特定的标题

X Y - [R图例

5 6 0.1 1

....

等。我想用最后一列作为标题分配给圈子。有没有办法做到这一点?

回答

1

这取决于您想如何显示相应的“标题”。让我们假设数据文件包含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' 

这将产生: enter image description here

另外,人们可能希望把这些标签到图形的传说。或许有一个更好的解决方案,但是一种方法是 图中的数据文件的每一行分别与手动提取第四列(被用作密钥标题):

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 $4}' '%s'", i+1, fName)) 

这给出: enter image description here

相关问题