代码之家  ›  专栏  ›  技术社区  ›  Nehil Danış

如何在gnuplot中为数据文件中的每一行指定特定标题

  •  1
  • Nehil Danış  · 技术社区  · 7 年前

    我有一个数据文件,它保存了绘制圆的所有x、y坐标和半径值。每个圆代表一个区域。到现在为止,我画了圆圈。但我想为数据文件中的每一行指定特定的图例。因为在绘制区域后,我想在这个区域上放置一些点,取决于区域数。然而,我不知道该怎么做。是否有人知道如何根据数据文件中的行号为圆指定特定图例。数据文件看起来像

    X Y R图例

    ....

    以此类推。我想用最后一列作为标题来分配给圆。有什么办法吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   ewcz    7 年前

    这取决于您希望如何准确显示相应的“标题”。假设数据文件 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