我有两个不同的文件要在 gnuplot 中绘制。他们使用 a) 不同的分隔符 b) x 轴上的不同时间
因此,为了让他们每个人分别绘图,我需要通过
set datafile separator
set timefmt
我想在一个图表中强加/叠加两个数据,使它们与时间对齐
我怎么能这样做?
我有两个不同的文件要在 gnuplot 中绘制。他们使用 a) 不同的分隔符 b) x 轴上的不同时间
因此,为了让他们每个人分别绘图,我需要通过
set datafile separator
set timefmt
我想在一个图表中强加/叠加两个数据,使它们与时间对齐
我怎么能这样做?
可以通过使用using 修饰符后的格式为每个文件指定不同的分隔符来解决不同分隔符的问题,例如:
plot 'file1.dat' u 1:2 '%lf,%lf'
绘制带有逗号分隔符的两列文件。有关更多详细信息,请参阅帮助\使用。
我不是时间格式专家,所以我不知道如何处理时间戳格式问题。但也许你可以使用一些功能,比如strftime()
. 我从未尝试过,但在我看来它可以满足您的需求。
set datafile separator
你是对的,你需要通过set timefmt
每个文件一次。你可以这样做:
set terminal <whatever>
set output <whatever.wht>
set xdata time # tell gnuplot to parse x data as time
set format x '%F' # time format to display on plot x axis
set datafile separator ' ' # separator 1
set timefmt '%F' # time format 1
plot 'file1'
set datafile separator ',' # separator 2
set timefmt '%s' # time format 2
replot 'file2'
该replot
命令本身会重新绘制上一行,如果您指定要绘制的另一行将像我在这里所做的那样位于第一行之上。
在我看来,您有两个选择。首先是选择一种数据文件格式并将两个数据文件都转换为该格式,可能使用awk
:
plot '<awk "-f;" "{print $1,$2}" data1' using 1:2 w lines,\
'data2' using 1:2 w lines
*注意,您的 awk 命令几乎肯定会有所不同,这只是说明如何awk
在内联管道中使用。
您的第二个选项是使用multiplot
显式轴对齐:
set multiplot
set xdata time
set datafile sep ';' #separator for first file
set timefmt "..." #time format for first file
set lmargin at screen 0.9
set rmargin at screen 0.1
set tmargin at screen 0.9
set bmargin at screen 0.1
unset key
plot 'data1' u 1:2 w lines ls 1 nontitle
set key #The second plot command needs to add both "titles" to the legend/key.
set datafile sep ',' #separator for second file
set timefmt "..." #time format for second file
unset border
unset xtics
unset ytics
#unset other stuff that you set to prevent it from being plotted twice.
plot NaN w lines ls 1 title "title-for-plot-1", \
'data1' u 1:2 w lines ls 2 title "title-for-plot-2"
NaN
仅当您想让事物在图例中正确显示时,才需要使用情节技巧。如果您不使用图例,则不必担心。
这对我有用:
reset
set term pngcairo
set output 'wall.png'
set xlabel "Length (meter)"
set ylabel "error (meter)"
set style line 1 lt 1 linecolor rgb "yellow" lw 10 pt 1
set style line 2 lt 1 linecolor rgb "green" lw 10 pt 1
set style line 3 lt 1 linecolor rgb "blue" lw 10 pt 1
set datafile separator ","
set key
set auto x
set xtics 1, 2, 9
set yrange [2:7]
set grid
set label "(Disabled)" at -.8, 1.8
plot "file1.csv" using 1:2 ls 1 title "one" with lines ,\
"file2.csv" using 1:2 ls 2 title "two" with lines ,\
"file3.csv" using 1:2 ls 3 title "three" with lines
set output