Gnuplot绘制文件中的数据到某一行

YBE*_*YBE 36 plot gnuplot

我在一些文本文件中有数据,可以说10000行和2列.我知道我可以轻松地绘制它plot "filename.txt" using 1:2 with lines.然而我想要的只是绘制让我们说1000到2000的行或任何其他合理的选择.是否可以轻松地做到这一点?非常感谢你提前.

Stu*_*nge 79

似乎gnuplot 中的"every"命令正是您所寻找的:

plot "filename.txt" every ::1000::2000 using 1:2 with lines
Run Code Online (Sandbox Code Playgroud)

或者,预处理文件以选择您感兴趣的行.例如,使用awk:

awk "NR>=1000 && NR<=2000" filename.txt > processed.txt
Run Code Online (Sandbox Code Playgroud)

然后在现有的gnuplot命令/脚本中使用生成的"processed.txt".


kev*_*kev 31

更简单:

plot "<(sed -n '1000,2000p' filename.txt)" using 1:2 with lines
Run Code Online (Sandbox Code Playgroud)

  • 有什么好的在线资料,我可以学习这种小巧的技巧.谢谢你的回复btw. (2认同)
  • 以下答案是更好的选择! (2认同)

mgi*_*son 9

您可以使用伪列0来减少对外部实用程序的依赖(例如,如果您的系统没有安装它们).

看到 help plot datafile using pseudocolumn

尝试类似的东西:

LINEMIN=1000
LINEMAX=2000

#create a function that accepts linenumber as first arg
#an returns second arg if linenumber in the given range.
InRange(x,y)=((x>=LINEMIN) ? ((x<=LINEMAX) ? y:1/0) : 1/0)

plot "filename.txt" using (InRange($0,$1)):2 with lines
Run Code Online (Sandbox Code Playgroud)

(在Gnuplot 4.4.2,Linux上测试)