1

我有一个包含许多数据列的数据文件,前两行如下所示:

#time a1 b1 c1 d1 a2 b2 c2 d2 
1 2 3 4 5 6 7 8 9

我想在图表上加上一个标题,如下所示:

a1=2, a2=6, b1=3, b2=7, c1=4, c2=8, d1=5, d2=9

所以,基本上只是从第一行获取数据并添加一些文本。这可能吗?

谢谢麦吉尔森!这是脚本(第一部分。)

#filename = "a6_a.txt"

//defining variables called ofac and residual

unset multiplot
set term aqua enhanced font "Times-Roman,18" 

set lmargin 1
set bmargin 1
set tmargin 1
set rmargin 1
set multiplot
set size 0.8,0.37

set origin 0.1,0.08  #bottom
 set xlabel "time" offset 0,1  #bottom

 set ylabel "{/Symbol w}_i - {/Symbol w}_{i+1}"
 set yrange [-pi:pi]
 plot filename using 1:(residual($7 -$14)) ti "" pt 1 lc 2, \
            "" using 1:(residual($14-$21)) ti "" pt 1 lc 3, \
            "" using 1:(residual($21-$28)) ti "" pt 1 lc 4

set origin 0.1,0.36 #mid
 set format x ""    #mid, turn off x labeling
 set xlabel ""      #mid
 set ylabel "P_{i+1}/P_i" offset 2,0
 set yrange [*:*]
 plot filename using 1:(($10/ $3)**1.5) ti "P_2/P_1" pt 1 lc 2, \
            "" using 1:(($17/$10)**1.5) ti "P_3/P_2" pt 1 lc 3, \
            "" using 1:(($24/$17)**1.5) ti "P_4/P_3" pt 1 lc 4


set origin 0.1,0.64 #top
 set ylabel "semi-major axes"
 set yrange [*:*]
 plot filename using 1:($3):($4*$3) with errorbars ti "" pt 1 lc 1, \
   "" using 1:($10):($10*$11) with errorbars ti "" pt 1 lc 2, \
   "" using 1:($17):($17*$18) with errorbars ti "" pt 1 lc 3, \
   "" using 1:($24):($24*$25) with errorbars ti "" pt 1 lc 4

unset multiplot
unset format 
unset lmargin
unset bmargin
unset rmargin
unset tmargin
4

1 回答 1

0

你可能只能使用 gnuplot 来做到这一点(我认为),但这会很痛苦。最简单的解决方案是编写一个外部脚本,它将为您格式化标题 - 例如在 python 中(未经测试):

#python script formatTitle.py
import sys
fname=sys.argv[1]
with open(fname,'r') as f:
    line1=f.readline().split()
    line2=f.readline().split()

pairs=sorted(zip(line1,line2)[1:])
print (", ".join("%s=%s"%(p[0],p[1]) for p in pairs))

然后在gnuplot中:

set title "`python formatTitle.py datafile.dat`"    

编辑

您上面的脚本有一些问题。首先,//不是 gnuplot 中的注释字符——所以这会立即引发某种语法错误。接下来,您将filename其用作字符串变量(这没关系),但您尚未在任何地方定义它。(脚本的第一行可能会起作用,除非它已被注释掉)。最后,我无法检查,因为我没有您的数据文件,但是您对lmarginetc ++set size的使用set origin(对我来说)有点难以跟踪。更聪明的人可能对此没有问题。但是,当我想明确对齐我的图时,我使用margin.

#make plots go from 0.1 to 0.9 on the screen (screen range is 0-1)
# (0,0) is the lower left corner, (1,1) is the upper right.
set lmargin at screen 0.1
set rmargin at screen 0.9 

然后对于每个子图,您可以执行以下操作:

NPLOTS=3
SCREENSIZE=0.8  #leave .1 for the top and bottom border
DY=SCREENSIZE/NPLOTS #height of each plot

#bottom
set tmargin at screen 0.9-2*DY
set bmargin at screen 0.9-3*DY
#other commands
plot ... 

#middle
set tmargin at screen 0.9-DY
set bmargin at screen 0.9-2*DY
#other commands ...
plot ...

#top
set tmargin at screen 0.9
set bmargin at screen 0.9-DY
#other commands ...
plot ...

当然,您可以根据自己的喜好调整位置。

于 2012-06-06T20:24:37.970 回答