1

I am currently plotting graphs from multiple files. The data are basically time series with a timestamp in the first column and multiple measurements in the other columns. The timestamps do not exactly match in all files. Nevertheless I would like to plot the graphs stacked on top/above of the others. Has gnuplot means to facilitate that - e.g. also doing interpolation where necessary?

file1:

0.1 42 1 100
0.2 43 0 102
0.3 45 -2 105

file2:

0.15 38 -3 88
0.25 37 -2 88.5

plot 'file1' using 1:2 w l, 'file2' using 1:2 w l STACK_ME_PLEASE

So in this example I would like to show the points from file2 roughly at (0.15, 42.5+38) and (0.25, 44+37) - that is stacked on top of the graph from file1.

R. García
  • 815
  • 9
  • 20
user1225999
  • 912
  • 8
  • 14
  • gnuplot can do quite a lot of things. But you are asking for quite a lot here. I suggest you do some preprocessing on file2 to create a file3 to plot with file1. Do that in C, C++, Java, Fortran, R, in excel if its not to big. – Dan Sp. Aug 02 '18 at 03:19

1 Answers1

0

In case this is still relevant, the following code covers your example, however, since you do not provide information about your general data, the following suggestion might not work in a more general case. The data is only "stacked" if the data of the second file is exactly in the middle of two datapoints of the first file. Maybe with some extra effort it can be adapted in such a way that it still "stacks" the data if it is just somewhere between two datapoints of the first file.

Code:

### "stacking" data
reset session

$Data1 <<EOD
0.1   42   1   100
0.2   43   0   102
0.3   45  -2   105
EOD

$Data2 <<EOD
0.15   38   -3   88
0.25   37   -2   88.5
EOD

set table $Data3
    plot x1=y1=NaN $Data1 u (x0=x1,x1=$1,(x0+x1)/2.):(y0=y1,y1=$2,(y0+y1)/2.) w table
    plot $Data2 u 1:2 w table
unset table

set table $Data4
    plot $Data3 u 1:2 smooth freq
unset table

set yrange [0:]
set key top left

plot $Data1 u 1:2 w lp pt 7 lc "red", \
     $Data2 u 1:2 w lp pt 7 lc "web-green", \
     $Data4 u 1:2 w lp pt 7 lc "cyan"
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • @user1225999 as you already mentioned it, in the general case you need to interpolate or resample your data. Unfortunately, there is no intrinsic gnuplot function for it. So, you have to use external tools or you can try this cumbersome gnuplot workaround: https://stackoverflow.com/q/54362441/7295599 – theozh Apr 15 '21 at 07:28