gnuplot:在单个图形中打印来自多个输入文件的数据

gnuplot:在单个图形中打印来自多个输入文件的数据,gnuplot,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"

我正在尝试使用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\u 401275
  • print_401276
它给出了一个奇怪的错误,如下所示:

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

我做错什么了吗?可以在同一个图形中绘制不同文件的输入数据吗?

你太接近了

改变

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"


出现错误的原因是,gnuplot试图将单词“plot”解释为要打印的文件名,但您没有为名为“plot”的变量分配任何字符串(这很好,会让人非常困惑)。

如果您适当调整文件名或图形标题,您可能会发现gnuplot的for循环在这种情况下很有用

e、 g


replot

这是一次获取多个绘图的另一种方法:

plot file1.data
replot file2.data

聪明一点,转到这个话题我知道这个话题很老了,但是谢谢你添加了这个替代方案。我不知道gnuplot中有循环,它们是一个惊人的特性。假设文件名约定(name.dat)正常,我认为应该是file.“.dat”。第一个。将文件名连接到“dat”,但不包括在打印命令中实际使用的文件名中。如何在不显式写入文件名的情况下打印目录中的所有文件?()我给这个问题加了一个答案,@becko。最好的答案,第一个不起作用。输出为:“格式必须有1-7个双精度(%lf)类型的转换”。而其他选项仅允许您在所有数据列都相同的情况下执行此操作。
filenames = "first second third fourth fifth"
plot for [file in filenames] file."dat" using 1:2 with lines
filename(n) = sprintf("file_%d", n)
plot for [i=1:10] filename(i) using 1:2 with lines
plot file1.data
replot file2.data