I have two files file1.dat and file2.dat that each contain a matrix (say, F1 and F2, respectively) that agree in dimensions (i.e. they're both m x n matrices). I know how to use gnuplot to plot either of them (splot "file1.dat" matrix for instance), but how do I instruct gnuplot to plot F1-F2?
3
votes
2 Answers
1
votes
Unfortunately, (to my knowledge) there is no way to plot information from multiple files using gnuplot. The solution is to write a simple script (in your favorite language) that takes the two files as input and writes the difference as output... Then you could do:
splot "<myscript file1.dat file2.dat" matrix ...
I'm sure that with enough coaxing, using set table and shell magic, I could come up with a hack to do what you want (having gnuplot output multiple datafiles, issuing shell commands to paste the datafiles together ...), but in the end, writing your own script would be a much cleaner solution.
1
votes
Here is a working example using a bit of awk in gnuplot.
set terminal postscript enhanced colour
set output 'matrixdiff.eps'
unset key
splot "<awk 'NR==FNR{for(i=1;i<=NF;++i)a[FNR,i]=$i;next}{for(i=1;i<=NF;++i)$i=a[FNR,i]-$i;print}' mat1 mat2" matrix
mat1 and mat2 are the matrix files you want to plot. The awk script is from here.