带有一组数据文件。我想对每个文件执行一系列操作(例如拟合),并将结果曲线与我的分析一起连续堆叠(以查看每个曲线如何适合更大的画面)。我写了以下代码片段
reset
PATH = 'XRP_'
nmin = 1
nmax = 20
f(x) = log10(x); h(x) = a*x + b
name(i) = sprintf(PATH.'%04d/data_main_ddnls_twod_mlce.dat', i)
set xrange [0:7]
start = 0
set fit
do for [i=nmin:nmax]{
fit [4:] h(x) name(i) using (f($1)):(f($4)) via a, b
if (start==0){
plot name(i) using (f($1)):(f($4)) w l title sprintf("%04d", i)
} else {
replot name(i) using (f($1)):(f($4)) w l title sprintf("%04d", i)
}
start = start + 1
pause -1
}
# Add the slope
replot (1./5.)*x + 0.5 lc 'black' lw 3 dt 2
unset fit
# pause -1
与其叠加所有先前的曲线和当前曲线,不如将其绘制为i倍(参见代码循环)。例如,经过10次迭代后,它仅绘制第10个数据文件10次(请参见图片中的图例)
我怎样才能解决这个问题?
您的绘图按照其行为方式工作的原因,以及theozh的示例(1)也是如此,是因为“ replot f(x)”通过在前面的plot命令的末尾加上“,f(x)”来起作用。通过将其放入循环中,基本上就是在创建连续的命令
plot f(x,i)
plot f(x,i), f(x,i)
plot f(x,i), f(x,i), f(x,i)
...
是的,i的值可能每次都会更改,但是尽管如此,每个plot命令都会生成同一事物的多个副本。
替代解决方案:我通常不建议使用多图模式来创建单个输出,但是在这种情况下,它可能是最佳选择。
# force identical margins even if the range changes
set margins screen 0.1, screen 0.9, screen 0.1, screen 0.9
# ... same prelimary stuff as shown in the question
# revised loop using multiplot rather than replot
set multiplot
do for [i=nmin:nmax]{
fit [4:] h(x) name(i) using (f($1)):(f($4)) via a, b
plot name(i) using (f($1)):(f($4)) w l \
title sprintf("%04d", i) at screen 0.9, screen 1.0 - 0.02*i
unset tics
}
unset multiplot
请注意,您不能使用自动生成的标题放置位置,因为每次多次绘图都会将标题放置在同一位置。因此,我们改为使用“ title foo at”的形式。同样,最好在第一遍之后关闭tic生成,这样您就不必在每次循环时都重新绘制tic和标签。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句