Gnuplot: 在一个图中绘制来自多个输入文件的数据

我正在尝试使用 gnuplot 绘制图表。我有六个文本文件。每个文本文件包含两列。第一列表示以秒为单位的时间(浮点数)。第二个是序列号。我想把时间与序列号的关系图绘制在一个图中,用于所有六个文件。我正在用这个文件做这件事。

set terminal png
set output 'akamai.png'


set xdata time
set timefmt "%S"
set xlabel "time"


set autoscale


set ylabel "highest seq number"
set format y "%s"


set title "seq number over time"
set key reverse Left outside
set grid


set style data linespoints


plot "print_1012720" using 1:2 title "Flow 1", \
plot "print_1058167" using 1:2 title "Flow 2", \
plot "print_193548"  using 1:2 title "Flow 3", \
plot "print_401125"  using 1:2 title "Flow 4", \
plot "print_401275"  using 1:2 title "Flow 5", \
plot "print_401276"  using 1:2 title "Flow 6"

我的文件在哪里:

  • print_1012720
  • print_1058167
  • print_193548
  • print_401125
  • print_401275
  • print_401276

它出现了一个奇怪的错误,如下所示:

“ plot.plt”,第24行: 未定义的变量: plot

我是不是做错了什么? 有没有可能将不同文件的输入数据绘制在同一个图表中?

222670 次浏览

You're so close!

Change

plot "print_1012720" using 1:2 title "Flow 1", \
plot "print_1058167" using 1:2 title "Flow 2", \
plot "print_193548"  using 1:2 title "Flow 3", \
plot "print_401125"  using 1:2 title "Flow 4", \
plot "print_401275"  using 1:2 title "Flow 5", \
plot "print_401276"  using 1:2 title "Flow 6"

to

plot "print_1012720" using 1:2 title "Flow 1", \
"print_1058167" using 1:2 title "Flow 2", \
"print_193548"  using 1:2 title "Flow 3", \
"print_401125"  using 1:2 title "Flow 4", \
"print_401275"  using 1:2 title "Flow 5", \
"print_401276"  using 1:2 title "Flow 6"

The error arises because gnuplot is trying to interpret the word "plot" as the filename to plot, but you haven't assigned any strings to a variable named "plot" (which is good – that would be super confusing).

You may find that gnuplot's for loops are useful in this case, if you adjust your filenames or graph titles appropriately.

e.g.

filenames = "first second third fourth fifth"
plot for [file in filenames] file."dat" using 1:2 with lines

and

filename(n) = sprintf("file_%d", n)
plot for [i=1:10] filename(i) using 1:2 with lines

replot

This is another way to get multiple plots at once:

plot file1.data
replot file2.data