Gnuplot can easily plot data from multiple files in the same plot.
plot "A.dat", "B.dat"
It can also combine values from different columns of a single input file.
plot "A.dat" using 1:($2+$3)
A frequently asked question is "how can I combine values from columns in multiple input files?". The answer is that you can't, you must instead process the data outside gnuplot so that all the needed values are in the same file.
The new "merge" command overcomes this long-standing limitation. It allows you to merge coordinate values from component graphs in the previous plot command into a single data block. Here is the documentation entry for this first draft of a patch implementing the merge command:
merge
command extracts certain values from the preceding plot
commandmerge
command.==========
Unresolved issues (please comment):
Currently the same x-values must appear in all of the merged plots.
It seems desirable to allow missing data points. How?
If the preceding plot contained both data and function graphs, the merge
command will probably complain about mis-matched x values. This is an
example of the above issue. Should it simply ignore functions?
Currently the merge command ignores xrange. Should it?
Is there a better name for the new command? I considered
"fill" "keep" "store" "extract" "combine" among other possibilities.
The interactive terminals now allow you to toggle individual graphs on/off.
Should a subsequent "merge" command only merge data from graphs that have
not been toggled off?
My own likely use of this option would require tracking error values associated
with each Y value. Since this first version of the patch only tracks a single
value per point, producing a merged data block containing both the Y values and
the error values is somewhat cumbersome. Should the basic command have an
option to merge 2 data values from each existing graph?
Hi,
I had a look at this new
merge
command, not from the concrete implementation but rather the concept.I would have expected a command, which really merges two files before any plotting, akin to the
paste
command line tool.That would be a bit like the
stats
command which retrieves some data information (e.g. ranges, number of records) which can be used for plotting and which before that was only possible by first plotting e.g. to a table or to /dev/null and then using the gnuplot-internal variables for the next, real plot.Maybe the syntax could be something like
That may also be combined with reading datablocks from a file to extend the
volatile
keyword, see e.g. bug #1233.Or what is the reason that
merge
must be preceeded by aplot
command?I´d recommend to not use "plot" to load the datasets, but implement a "load" command that creates a matrix variable containing the data, eg.
load filename1 datamatrix1 using 1:2
load filename2 datamatrix2 using 1::2
The matrix variables could contain any number of columns. The merge command then takes each line from matrix one, and checks if the value in the selected column appears in the other matrix. If so, the respective lines are combined in a third matrix:
merge datamatrix1[0] AND datamatrix2[0] to andmatrix[0]
(OR/XOR/NOT could then also be implemented )
If no columns are specified with "merge", then only line numbers are compared. This would resolve most of the issues mentioned. Drawback is that only two datasets can be combined at a time.
Here´s of course a slippery slope to implement a new matlab/octave. ;-)
see https://github.com/magiccpp1/merge_curves/wiki
you could utilize the interpolation to calculate it. i.e.
file dataset1:
1.2 5.0
2.3 3.5
3.8 3.0
file dataset2:
0.8 2.0
1.5 3.0
2.5 4.0
output:
0.8 0.0 2.0 # contribution from 1st array is 0, it is out of x range, from 2nd is 2.0
1.2 5.0 7.57 #5.0 + 2.0 + (1.2-0.8) * (3.0-2.0)/(1.5-0.8) contribution from 1st array is 5.0, from 2nd is 2.57
1.5 4.6 7.6 #3.0 + 5.0 + (1.5 - 1.2) * (3.5 - 5.0) / (2.3 - 1.2) contribution from 1st array is 4.6, 2nd is 3.0
2.3 ...
2.5 ...
3.8 3.0 0.0 #contribution from 2nd array is 0, it is out of x range.
Last edit: magiccpp 2015-04-19